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.
Note that just calling history.pushState () or history.replaceState () won't trigger a popstate event. The popstate event will be triggered by doing a browser action such as a click on the back or forward button (or calling history.back () or history.forward () in JavaScript).
Using Ajax and trying to create a popstate event handler on the actual Ajax page using the .document object: Unfortunately this does not ever seem to trigger. My intention being that after the page is reloaded the popstate event trigger will automatically disappear. Show activity on this post.
Unfortunately this does not ever seem to trigger. My intention being that after the page is reloaded the popstate event trigger will automatically disappear. Show activity on this post.
The addEventListener () method attaches an event handler to a document. Required. The event name. Do not use the "on" prefix. Use "click" instead of "onclick". HTML DOM Event Object Reference.
inside ajax success response , you could use
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
}
UPDATE
$(window).unload(function(e){
e.preventDefault();
$(window).trigger('beforeunload');
});
$(window).bind('beforeunload',function(){
alert('call your ajax here');
return '';
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With