单击后退按钮时,使浏览器忽略URL哈希 [英] Making browsers ignore the URL hash when the back button is clicked
本文介绍了单击后退按钮时,使浏览器忽略URL哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,如果用户在 http://example.com 上,则该用户转到 http://example.com#comments 。如果用户在浏览器上点击返回,我怎样才能让他忽略 http://example.com 和直接转到他之前访问过的URL?
For example, if an user is on http://example.com, then the user goes to http://example.com#comments. If the user clicks "back" on his browser, how can I make him "ignore" http://example.com and go directly to the URL that he visited before that?
我已经加载了jQuery。
I have jQuery loaded.
推荐答案
而不是像以下链接:
<a href='#comments'>Link</a>
使用 location.replace()
来在浏览器的历史记录中覆盖 http://example.com
的记录。
Use location.replace()
to "overwrite" the record of http://example.com
in the browser's history.
https://developer.mozilla.org/en/DOM/window.location
示例:
HTML:
<a id='commentsLink'>Link</a>
JavaScript:
JavaScript:
$("#commentsLink").click(function(){
window.location.replace("#comments");
});
这篇关于单击后退按钮时,使浏览器忽略URL哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文