onpopstate handler - ajax back button

前端 未结 3 1365

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:33

    //example: http://www.nseri.com/news/5536

    window.onpopstate = function(e) {
         var count = String(location.pathname).split('/').length;
         if (count<4) {
              location.href = location.href;
         }else {
              $.ajaxLoad(location.pathname);
         }
    }
    

提交回复
热议问题