6

使用 Ajax 并尝试使用 .document 对象在实际的 Ajax 页面上创建 popstate 事件处理程序:

document.addEventListener("popstate", myPopState);

不幸的是,这似乎永远不会触发。

我的意图是在页面重新加载后 popstate 事件触发器将自动消失。

4

1 回答 1

1

在ajax成功响应中,您可以使用

         var msg="Any thing which u want";
         var customUrl ="www.stackoverflow.com";

 window.history.pushState({"html":msg,"pageTitle":"My Title"},"", customUrl);
       window.onpopstate = function(event) {
             alert('back is clicked');
           // what ever u want
       }

更新

$(window).unload(function(e){
    e.preventDefault();
    $(window).trigger('beforeunload');   

});


$(window).bind('beforeunload',function(){

alert('call your ajax here');
    return '';
});
于 2016-09-15T16:21:41.980 回答