Javascript examples for DOM:Element addEventListener
Add event handler to window with addEventListener method
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from w w w . jav a 2 s. c o m window.addEventListener("beforeunload", function (evt) { evt.returnValue = "my message"; }, false); } </script> </head> <body> <a href="http://java2s.com">website</a> </body> </html>