[BUG] JavaScript Adventures of pseudo protocol trigger onbeforeunload

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

According to the description of MSDN, IE onbeforeunload event trigger conditions:

Simple is the page URL to change the trigger:

* Close the browser window
* Click the back, forward, refresh, home page
* Click on the link to the new page
* Call the click hyperlink,document.write,document.open,document.close
* Call window.close, window.open[_self], winodw.navigate, NavigateAndFind, location.replace, location.reload, new location.herf, submit form submit,form.submit

Then have a look JavaScript pseudo protocol trigger onbeforeunload:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<a href="javascript:;">I am a, I try to link javascript:;</a> 
<a href="javascript:void(0);">I'm a javascript:void link (0); I try,</a>
<a href="#">I'm a link #, I try</a>

<script type="text/javascript">

  //javascript:; And javascript:void (0); both the trigger onbeforeunload

window.onbeforeunload = function (e) { e = e || window.event; // Compatible with IE8 and Firefox versions prior to 4 if (E) {e.returnValue = 'close';} // Chrome, Safari, Firefox 4+, Opera 12+, IE 9+ return 'close tips'; }; </script> </body> </html>

Solution:  

Onbeforeunload is not standardized, the browser support and trigger different!

Avoid the use of Javascript: in the page; and other pseudo protocol, to avoid repeated trigger onbeforeunload
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Bruno at November 15, 2013 - 10:46 PM