开发者

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 is true, causes the page to always be reloaded from the server. If it is false 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜