我按照以下方式使用 History.js for jQuery(v1.7.1,html4+html5 bundle )
在我的js文件顶部准备:
(function(window,undefined){
// Prepare
var History = window.History; // Note: We are using a capital H instead of a lower h
if ( !History.enabled ) {
// History.js is disabled for this browser.
// This is because we can optionally choose to support HTML4 browsers or not.
return false;
}
// Bind to StateChange Event
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
var State = History.getState(); // Note: We are using History.getState() instead of event.state
History.log(State.data, State.title, State.url);
});
})(window);
然后在我的代码中进一步:
$foo.click(function(e) {
e.preventDefault();
History.pushState({}, "", "?" + bar);
});
基本上我想要实现的是,每次单击某些项目时,查询字符串 "?"+ bar
附加到 url 后,pushState 将其存储在浏览器历史记录中。这在最新的 FF 中工作得很好,但在 IE7 中测试时,会出现以下类似警报的消息:
弹出窗口中的网址是我所期望的网址,即使在浏览器中它显示为
http://www.foobar.com/.../#?Fixed
也就是说,带有额外的哈希值。但令我担心的是错误消息 - 有任何线索吗?
最佳答案
仅供记录,如果有人再次出现在该页面上 - 我已隔离脚本并且错误不再发生。经过漫长而繁琐的测试,我发现这是由于与专有的 jquery 插件冲突引起的,并修复了它。
关于javascript - jQuery 的 History.js 在 IE7 中触发不需要的 "alert",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11650984/