How do I refresh a page with a hash?
I refresh pages by writi开发者_Python百科ng window.location = window.location;
. However this doesn't work on a page like /page#c22. It will just jump to whereever c22 is. How do I refresh the page?
It does not need to use go to #c22 once refreshed but I am sure there is a more dependable way than window.location = window.location
.
You may want to try:
window.location.reload(true);
reload(forceget)
: Reload the document from the current URL.forceget
is a boolean, which, when it istrue
, causes the page to always be reloaded from the server. If it isfalse
or not specified, the browser may reload the page from its cache. (Source)
You can use this:
window.location.reload();
The spec for this is here, at the W3C
This function forces the host application to reload the resource identified by the Location.
Try:
location.reload(true)
"Page auto reload with parameters" is one tried to preserve get parameters.
Probably you wanted to use location.pathname.
精彩评论