html - chrome 和 firefox 中的 onpopstate

标签 html firefox google-chrome

我使用 pushStateonPopState 来创建 ajax 导航。

但是这里有个小问题。

在第一次访问页面或页面刷新时,chrome 会触发 onPopState 事件,但 firefox 不会。

这会导致 chrome 加载内容两次,但 firefox 运行良好。

我不知道哪个是正确的,我该如何解决这个问题?

似乎这种行为在旧版本中是相反的:))

HTML5 onpopstate on page load

最佳答案

我解决的问题:

window.onpopstate = function(event) 
{
    if (!event.state) return;
    ajaxPage(document.location.href);
};

关于html - chrome 和 firefox 中的 onpopstate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11700941/

相关文章:

debugging - 如何调试 Angular JavaScript 代码

javascript - onmousedown 调用鼠标捕获函数?

Android Chrome 第二次安装横幅

google-chrome - Chrome DevTools Snippets 存储在 Chrome 90 中的什么位置?

javascript - html 和 javascript 中的生活游戏不起作用

html - 使表格与图像部分重叠

html - CSS 按钮在 Safari 8 中损坏,但在 Chrome、FF、IE 中正常

java - 使用 FirefoxProfile 以编程方式打开 Firefox 开发工具

javascript - 除非我使用 Chrome 禁用网络安全,否则 HttpRequest 会失败

php - 在 Twitter 上分享 URL : HTTP or HTTPS?