2012-07-06 20 views
1

我有這個html頁面。在Chrome,如果我點擊Button2的幾個時間,然後點擊導航後退按鈕爲什麼popstate不會在Firefox中觸發

<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

回答

0

上發現另一個問題管理的歷史和幫助過我:

popstate不應該當你點擊被稱爲鏈接。當用戶使用後退/前進按鈕導航時調用 。

一切都在按照它應有的方式工作。

相關問題