onpopstate handler - ajax back button

前端 未结 3 1367

I\'m using pushState to create meaningful urls for ajax content on my site. I want to refresh the ajax content when the user hits the forward or back buttons. I\'m having pr

3条回答
  •  一生所求
    2020-12-11 04:25

    The object passed to the onpopstate function will have a state member, which will be null on the page load, so you could do something like this:

    window.onpopstate = function(event) {
      if(event && event.state) {
        // ...
      }
    }
    

提交回复
热议问题