2

I'm trying to detect if a user is leaving my websites. Like a window/tab close event of the webbrowser or by following a link to a other domain.

In some searches I found some solutions, but they alert ever when a link is clicked, also on my pages. As example I tried out this:

window.onbeforeunload = function(event) {

event = event || window.event;

var confirmClose = 'Are you sure?';

// For IE and Firefox prior to version 4
if (event) {
   event.returnValue = confirmClose;
}

// For Safari
return confirmClose;

}

So what do I have to modify so that the alert is deactivated when I'm browsing through my domain?

Thanks Oliver

Jesse Kernaghan
  • 4,544
  • 2
  • 18
  • 25
Oliver Becker
  • 161
  • 1
  • 8

1 Answers1

0

You can't know where you are going when the onbeforeunload fires. And the purpose is basically to prevent exactly what you are trying to achieve.

Pierre Gayvallet
  • 2,933
  • 2
  • 23
  • 37