0

below code will trigger a popup with Reload site? or Leave site? message on page refresh, press back button or on tab close

How to trigger this event only on tab close

window.addEventListener('beforeunload', function (e) {
   // Cancel the event
   e.preventDefault();
   // Chrome requires returnValue to be set
   e.returnValue = '';
 });
Arosha De Silva
  • 597
  • 8
  • 18

1 Answers1

0

There is no direct way of doing it because javascript doesen't have access to read browser actions. But if you want to do something on the server based on these actions, you may find this helpful.

Casper
  • 11
  • 2