Mukesh Patel
Mukesh Patel

Reputation: 147

how to call a function on [browser tab close,browser close,backforward,refresh]

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

Answers (2)

Behnam
Behnam

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

Yogen Darji
Yogen Darji

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

Related Questions