Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: How to truly reload a site with an anchor tag?

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.

like image 523
aefxx Avatar asked Feb 23 '10 14:02

aefxx


People also ask

How do I refresh a page using anchor tag?

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

How do you force refresh a page in JavaScript?

In JavaScript, you refresh the page using document. location. reload() . You can add the true keyword to force the reloaded page to come from the server (instead of cache).

How can I reload my current page without losing data?

The easiest way to reload the current page without losing form data, use WebStorage where you have -persistent storage (localStorage) or session-based (sessionStorage) which remains in memory until your web browser is closed. window. onload = function() { var name = localStorage.


1 Answers

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

like image 140
alemjerus Avatar answered Oct 11 '22 15:10

alemjerus