我有一个网站,它在浏览器栏中的主页上生成以下 URL:
http://example.com/int/bdf/eng/
我想将其更改为以下内容而不重新加载页面:
http://example.com
有可用的 IE8+ 解决方案吗?
我知道 window.history.pushState("", "", "");
但如何使用它?或者使用 htaccess 文件会更好吗?
最佳答案
根据W3C standards您可以使用位置哈希属性。
像这样的示例 URL:
http://www.example.com/test.htm#part2
location.hash 值将是:“#part2”和 here is a JSFiddle这向您展示了如何使用它。
关于javascript - 如何更改浏览器栏网址而不重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27502097/