popstate event handler seems not to work

前端 未结 3 1100
栀梦
栀梦 2020-12-11 16:02

I\'m having a problem with a \'popstate\' event handler, this is my code:

window.addEventListener(\"popstate\", function (event){
    if (event.state) {
             


        
3条回答
  •  情歌与酒
    2020-12-11 16:16

    No it will not,

    As per MDN documentation

    Note that just calling history.pushState() or history.replaceState() won't trigger a popstate event. The popstate event is only triggered by doing a browser action such as a click on the back button (or calling history.back() in JavaScript).

    Again as per this question the popstate event is not triggered in Chrome when you call pushState().

提交回复
热议问题