【发布时间】:2011-04-07 17:37:18
【问题描述】:
所以我看到很多人推荐隐藏的iFrame hack,即jQuery history plugin,但我真正需要的是这种技术的另一半:
function whenItemIsClicked()
{
window.location.hash = this.id;
//some other stuff, like Ajax
}
//and then, if page is reloaded...
$(document).ready(function(){
var loc = window.location.hash;
//if there happens to be a hash, navigate to corresponding content
if(loc != '') $(loc).click();
});
这两个都很好用。现在,我想附上这两行
var loc = window.location.hash;
if(loc != '') $(loc).click();
到一个事件,但似乎没有一个会被后退按钮一致触发。有没有办法添加浏览器历史状态来保存当前 URL,以便上述技术有效?
【问题讨论】:
标签: javascript jquery hashchange browser-state