2
我想了解HTML5歷史對象。這是一個我剛開始使用的簡單例子。javascript history onpopstate
function addDialog(){
document.getElementById('d').style.display ='';
history.pushState({name:"changed"},"","#newURL");
}
window.onpopstate = function(e){
alert(e.state);
}
我有一個div
用一個id爲d
這display
屬性爲none
。在點擊鏈接時,我會顯示div並更改歷史記錄,以便加載新的網址。
當我複製粘貼新網址時,popstate
事件被解僱,我得到null
爲e.state
。
據我所知,如果我加載新的網址http://example.com#newURL
,e.state
應該指向我使用pushstate推送的對象。
請糾正我,如果我錯了,我也想知道什麼時候e.state
得到填充。