How can I reload the page using JavaScript?
I need a method that works in all browsers.
How can I reload the page using JavaScript?
I need a method that works in all browsers.
This should work:
window.location.href = window.location.href.split( '#' )[0];
or
var x = window.location.href;
x = x.split( '#' );
window.location.href = x[0];
I prefer this for the following reasons:
Alternatively, you may use the most recent official method for this task
window.location.reload()
The Javascript reload() method is used to reload the current document or URL. The javascript location.reload(true) method work just like reload button in your browser. By default, the JS reload() method reloads the page from the cache, however you may force it to reload the page from the server side by setting the forceGet parameter to true: location. reload(true). Source: https://www.coderepublics.com/JavaScript/javascript-location-reload-true.php
What about Depricated? It is only the reload with forcedReload which is now deprecated. But to avoid depricated error you can use location.reload() without the forceReload flag.