views:

648

answers:

4

Take this code snippet for example:

window.location.href = 'mysite.htm#images';

Already being on the site mysite.htm and triggering the reload thru location.href won't reload the page but jump to the anchor named within the URL.

I need a mechanism to truly reload the page. Any ideas?

PS: I tried location's other methods but none of them does the trick :(

EDIT
Don't hang on the filetype htm. I'd need it for dynamic sites as well.

+1  A: 

You could be a cheater and append a randomized query string, redirecting to "mysite.htm?random=289954034#images".

But if this is a static page, as .htm implies, what do you need reloading for? If it's so that your onload Javascript can occur a second time, maybe you just need to change your application's flow.

Matchu
Don't let the extension fool you. You can just rewrite urls to make them look like they are html files.
Jage
It's true, but only rarely have I seen a rewriter choose `.htm` over `.html`. That's why I chose the word "implies" :)
Matchu
It's not about static vs. dynamic pages when AJAX comes into play. Think about it.
aefxx
...eh? Then you shouldn't need to refresh the page if you're using AJAX... I should probably just not try to analyze someone else's system without knowing any details at all xD
Matchu
+3  A: 

use the query part of the URL to add a random string:

// Use a timestamp to make sure the page is always reloaded
window.location.href = 'mysite.htm?r='+(+new Date())+'#images';
Andy E
A: 

Try this: window.location.href = 'mysite.htm?';

EDIT: This will only work the first time; after that, the caching takes effect again.

Cameron
+4  A: 

After you set the specified URL into location, issue window.location.reload(true). This will force browser to reload the page.

alemjerus
Haha, you're a genius, Sir. Dude, sometimes I'm not seeing the wood for the trees. Thanks.
aefxx