JavaScript之间有什么区别
window.location.href = window.location.href
Run Code Online (Sandbox Code Playgroud)
和
window.location.reload()
Run Code Online (Sandbox Code Playgroud)
功能?
假设我在一个名为"页面/example#myanchor1中myanchor的锚点"的页面上.我想链接到/example#myanchor2,但强制页面重新加载,同时这样做.
原因是我运行js来检测页面加载时url的锚点.这里的问题(通常是预期的行为)是,浏览器只是将我发送到页面上的特定锚点而不重新加载页面.
我该怎么做呢?JS没关系.
我知道我可以像这样在url的末尾添加一个哈希:
window.location.hash = '#myFancyHash';
Run Code Online (Sandbox Code Playgroud)
但由于各种原因,我需要完全重新加载页面.在某些浏览器上这很好用:
window.location = window.location.href + '#myFancyHash';
Run Code Online (Sandbox Code Playgroud)
但其他人拒绝重新加载页面,因为它将新网址视为哈希版本.
有没有办法强制所有浏览器重新重定向(重新加载)页面?