Reputation: 147
i need to code for browser in js/jQuery to execute/call a function on browser close, on browser tab close, back, forward, refresh.
Upvotes: 0
Views: 2419
Reputation: 6459
you can use this code
window.onbeforeunload = function(e) {
var dialogText = 'are you sure?';
e.returnValue = dialogText;
return dialogText;
};
support
Feature Chrome Edge Firefox (Gecko) IE Opera Safari
Basic support 1.0 (Yes) 1 4 12 3
Upvotes: 1
Reputation: 3300
You can use window.load
, window.onunload
and for back and forward use browser history
.
you can find more on https://developer.mozilla.org/en-US/docs/Web/API/History_API
Upvotes: 0