Using Ajax and trying to create a popstate event handler on the actual Ajax page using the .document object:
document.addEventListener("popstate", myPopState);
Unfortunately this does not ever seem to trigger.
My intention being that after the page is reloaded the popstate event trigger will automatically disappear.
Using Ajax and trying to create a popstate event handler on the actual Ajax page using the .document object:
document.addEventListener("popstate", myPopState);
Unfortunately this does not ever seem to trigger.
My intention being that after the page is reloaded the popstate event trigger will automatically disappear.
Share Improve this question asked Sep 15, 2016 at 16:18 NickCNickC 1,3535 gold badges16 silver badges23 bronze badges 1-
10
window.addEventListener("popstate", myPopState);
– zer00ne Commented Sep 15, 2016 at 16:20
1 Answer
Reset to default 1inside ajax success response , you could use
var msg="Any thing which u want";
var customUrl ="www.stackoverflow.";
window.history.pushState({"html":msg,"pageTitle":"My Title"},"", customUrl);
window.onpopstate = function(event) {
alert('back is clicked');
// what ever u want
}
UPDATE
$(window).unload(function(e){
e.preventDefault();
$(window).trigger('beforeunload');
});
$(window).bind('beforeunload',function(){
alert('call your ajax here');
return '';
});