开发者

How can I reload the entire page when only the url hash changes?

开发者 https://www.devze.com 2023-03-25 01:53 出处:网络
How do I reload a page if the onl开发者_如何学Goy change to the url is a hash? location.href doesn\'t work as I expect.

How do I reload a page if the onl开发者_如何学Goy change to the url is a hash? location.href doesn't work as I expect.

location.href= siteUrl + '#T_blockName';

This doesn't refresh the page unless I change siteUrl. How is it possible?


You need to use location.hash. This retrieves the hash. To change it, you need to use an anchor or set window.location to the location plus the hash you want.

Also, you are using PHP concatenation syntax when you should be using +.


Its possible because simply changing the hash part isn't going to request a page reload since hash is usually considered to be part of the page (anchor, id etc.).

You need to specifically request a page reload but how you are going to do it depends on what you are actually trying to achieve.


That is not how you concatenate strings in javascript, you need to use + instead of ..

location.href= CURRENT_SITE_URL + '#T_blockName';
0

精彩评论

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