[英]How can I reload the entire page when only the url hash changes?
How do I reload a page if the only change to the url is a hash? 如果唯一的URL更改是哈希,如何重新加载页面?
location.href
doesn't work as I expect. location.href
无法正常运行。
location.href= siteUrl + '#T_blockName';
This doesn't refresh the page unless I change siteUrl
. 除非我更改
siteUrl
否则不会刷新页面。 How is it possible? 这怎么可能?
You need to use location.hash
. 您需要使用
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. 要更改它,您需要使用锚点或将
window.location
设置为该位置以及所需的哈希值。
Also, you are using PHP concatenation syntax when you should be using +
. 另外,应在使用
+
时使用PHP串联语法。
That is not how you concatenate strings in javascript, you need to use +
instead of .
这不是在JavaScript中串联字符串的方式,您需要使用
+
而不是.
. 。
location.href= CURRENT_SITE_URL + '#T_blockName';
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.). 可能的原因是,仅更改哈希部分不会请求重新加载页面,因为通常认为哈希是页面的一部分(锚,ID等)。
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. 您需要专门请求页面重新加载,但是如何进行重新加载取决于您实际想要实现的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.