Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么popstate不';不要在Firefox中开火_Javascript_Html_Firefox_Browser History - Fatal编程技术网

Javascript 为什么popstate不';不要在Firefox中开火

Javascript 为什么popstate不';不要在Firefox中开火,javascript,html,firefox,browser-history,Javascript,Html,Firefox,Browser History,我有这个html页面。在chrome上,如果我在按钮2中多次单击,然后单击导航器返回按钮 <html> <head> <script> function button_onclick(){ var stateObj = { foo: "bar" }; history.pushState(stateObj, "page 2", "bar.html"); } function onPopState(){ console.log("loc

我有这个html页面。在chrome上,如果我在按钮2中多次单击,然后单击导航器返回按钮

<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>
如果我尝试Firefox,我什么都看不到?我用Firefow 13.0.1进行了测试
如果我想使用html5 history API管理历史记录,那真是太烦人了。

在另一个问题上找到并帮助我:

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

一切都按预期的方式运转

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