我这个页面在这里:
http://raidersleafs.com/andreaparliamentlaw/professional-development.html
如果您单击顶部的其中一个菜单项,请说“商业法”
它会重定向到这里:
http://raidersleafs.com/andreaparliamentlaw/index.html#business
网站的正确部分,但我希望删除#busness
网址,同时仍然去那个部分。我已经尝试过window.location.hash=""
并且有效,但它并没有把我带到网站的顶部而不是商业法......我希望这是有道理的,这可能吗?
谢谢,
发布于 2018-09-13 15:35:16
你可以这样做:
y = window.scrollY;
window.location.hash="";
window.scrollTo(0, y);
获取当前滚动位置,更改散列,然后滚动回到之前的位置。
或者你可以这样做:
history.pushState('', document.title, window.location.pathname);
这也将摆脱#
URL的末尾,然后你不必乱七八糟的滚动位置。
https://stackoverflow.com/questions/-100002628
复制相似问题