window.location.reload(); // If we needed to force the document to be fetched from the // web server again (such as where the document contents // change dynamically but cache control headers are not // configured properly), Firefox supports a non-standard // parameter that can be set to true to bypass the cache: //window.location.reload(true);
window.location.replace(window.location.pathname + window.location.search + window.location.hash); // does not create a history entry
window.location.href = window.location.pathname + window.location.search + window.location.hash; // creates a history entry
If you are refreshing after an
onclick then you’ll need to return false directly after
location.reload(); return false;
I was looking for some information regarding reloads on pages retrieved with POST requests, such as after submitting a
To reload the page keeping the POST data, use:
To reload the page discarding the POST data (perform a GET request), use:
window.location.href = window.location.href;
Hopefully this can help others looking for the same information.
You can perform this task using
window.location object can be used
- to get current page address (URL)
- to redirect the browser to another page
- to reload the same page
location object is like a fragment of the
window object and is called up through the
location object has three methods:
assign(): used to load a new document
reload(): used to reload current document
replace(): used to replace current document with a new one
So here we need to use
reload(), because it can help us in reloading the same document.
So use it like
To ask your browser to retrieve the page directly from the server not from the cache, you can pass a
true parameter to
location.reload(). This method is compatible with all major browsers, including IE, Chrome, Firefox, Safari, Opera.
This should work:
window.location.href = window.location.href.split( '#' );
var x = window.location.href; x = x.split( '#' ); window.location.href = x;
I prefer this for the following reasons:
- Removes the part after the #, ensuring the page reloads on browsers that won’t reload content that has it.
- It doesn’t ask you if want to repost last content if you recently submit a form.
- It should work even on most recent browsers. Tested on Lasted Firefox and Chrome.
Alternatively, you may use the most recent official method for this task
Hope you learned something from this post. The primary source of this article is StackOverflow.
Follow Programming Articles for more!