jquery - History.js 无限事件循环

标签 jquery history.js html5-history

我的history.js有问题

https://github.com/browserstate/history.js/

第3170行的事件onload处于无限循环

此事件的用途是什么?什么会触发它?!

只有在 Chrome 中我才会遇到这个问题

/**
         * Bind for Saving Store
         */
        if ( sessionStorage ) {
            // When the page is closed
            History.onUnload = function(){    // <----- this is triggeren in a loop
                // Prepare
                var currentStore, item, currentStoreString;

                // Fetch
                try {
                    currentStore = JSON.parse(sessionStorage.getItem('History.store'))||{};
                }
                catch ( err ) {
                    currentStore = {};
                }

enter image description here

最佳答案

在我评论了你的问题后,我很快就找到了解决方案。 History.js 报告了有关此行为的问题 here .

主要原因是 setInterval 调用,这是由于 IE8 的限制而存在的。代码中的问题是它适用于所有情况,而不仅仅是 IE8。

在主项目中的某个时间得到修复之前,可以通过编辑 History.js 第 #1992 行附近的代码来修复这种不必要的轮询。

// For Internet Explorer
if (History.isInternetExplorer() && History.getInternetExplorerMajorVersion() < 9) {
  History.intervalList.push(setInterval(History.onUnload, History.options.storeInterval));
}

关于jquery - History.js 无限事件循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21504638/

相关文章:

jquery - statechange 加载导致同一页面多次加载

javascript - window.onPopState() 事件处理程序可以知道导航方向吗? (向前向后)

javascript - 在不刷新的情况下加载新页面时 CSS 加载缓慢

javascript - 更改 window.location.hash 在历史记录中创建条目但不影响 chrome 后退按钮

javascript - 通过 JS 重新填充后调整 jQuery 内容 "drawer"的大小

javascript - 将 jQuery Ajax 请求的结果设置为全局变量

jquery - 将多个参数传递给 $.delegate

javascript - 在 Firefox Quantum 中刷新页面后丢失 window.history.state

javascript - Backbone.history.start 导致安全错误 18

jQuery .each() - 实际用途?