带有哈希标签的 JavaScript 重定向
我已经使用 History.js 通过 AJAX 实现了网站的搜索结果。对于 HTML5 浏览器,我有像 http://example.com/search/X6a2/3
这样的 URL,在不支持 History API 的浏览器中,它确实可以很好地回退到 http:// /example.com/search/#X6a2/3
。
但是,如果在较旧的浏览器中打开 HTML5 URL,则页面更改后,新的哈希标记将立即附加到完整 URL。 (例如 http://example.com/search/X6a2/3#/X6a2/4
- 呃!)
我所需要的只是一种干净的方法来尽快重定向到仅哈希标记版本当检测到非 HTML5 浏览器时。 window.location.replace()
似乎忽略了哈希标签。我该怎么办?
I have implemented my website's search results with AJAX, using History.js. For HTML5 browsers, I have URLs like http://example.com/search/X6a2/3
, which, in browsers not supporting the History API, does fall back nicely to http://example.com/search/#X6a2/3
.
However, if a HTML5 URL is opened in an older browser, the new hash tag is appended to the full URL as soon as the page is changed. (for example http://example.com/search/X6a2/3#/X6a2/4
- ugh!)
All I need is a clean way to redirect to the hash tag-only version as soon as a non-HTML5 browser is detected. window.location.replace()
seems to ignore the hash tag. What do I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎对我有用。您确定 window.replace 是问题所在吗?
This seems to work for me. Are you sure window.replace is the problem?