【发布时间】:2017-04-25 19:51:48
【问题描述】:
以下不起作用(我只是重新加载):
location.host += "/#settings";
location.reload();
我如何告诉 JS 导航到基于现有 url 的 URL 并完全重新加载该页面(而不仅仅是附加哈希)?
这也不起作用:
window.location.href = "/#settings";
我的基本网址是"http://localhost:sss/pricing"
我想通过重新加载重定向到"http://localhost:sss/#settings"。
我不想在任何地方输入localhost。
即使这给了我settings#lol:
var desiredBase = window.location.protocol + "//" + window.location.host + "/";
var path = '#lol';
window.location.href = desiredBase + path;
location.reload();
【问题讨论】:
-
@vso 不,这不适用于哈希。
-
window.location.href = "#settings"; ? -
and totally reload that page@nocodename -
嘿,试试他们在这里写的函数:stackoverflow.com/questions/25203124/…
标签: javascript html