javascript history onpopstate -
i trying understand html5 history object. here simple example started off with.
function adddialog(){ document.getelementbyid('d').style.display =''; history.pushstate({name:"changed"},"","#newurl"); } window.onpopstate = function(e){ alert(e.state); } i have div id d display property none. on clicking link, display div , change history new url loaded.
when copy paste new url, popstate event fired , null e.state.
from understand, if load new url http://example.com#newurl, e.state should point object pushed using pushstate.
please correct me if wrong , know when e.state gets populated.
as tested, e.state pop state add history when click in or forward button. otherwise, give null.
you can use parameters url can test if request came history call or url in location bar.
onpopstate = function(event) { alert('popevent: ' + event); if(event.state){ setuppage(event.state); } else { setuppage(getqstringparam('zid')); } }
Comments
Post a Comment