【问题标题】:Why popstate doesn't fire in Firefox为什么 popstate 在 Firefox 中不触发
【发布时间】:2012-07-06 22:18:14
【问题描述】:

我有这个 html 页面。在 chrome 上,如果我在 Button2 中单击几次,然后单击导航器后退按钮

<html>
<head>
<script>

function button_onclick(){
    var stateObj = { foo: "bar" };
    history.pushState(stateObj, "page 2", "bar.html");
}

function onPopState(){
    console.log("location: " + document.location + ", state: " + JSON.stringify(event.state));
}


window.addEventListener('popstate', onPopState, false);

</script>
</head>

<body>

<button type="button" onclick="button_onclick()">Button 2</button>

</body>

</html>

我可以在控制台看到:

location: http://somedomain:8080/examples/bar.html, state: {"foo":"bar"} 

如果我尝试使用 Firefox,我什么也看不到?我用 Firefow 13.0.1 测试过 如果我想使用 html5 历史 API 管理历史记录,这很烦人

【问题讨论】:

    标签: javascript html firefox browser-history


    【解决方案1】:

    发现另一个问题并帮助了我:

    单击链接时不应调用popstate。它是 当用户使用后退/前进按钮导航时调用。

    一切都按预期进行。

    【讨论】:

      猜你喜欢
      • 2021-07-16
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 2012-06-12
      • 2014-06-18
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多