Opening another window in Javascript when user presses X on browser - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window open

Description

Opening another window in Javascript when user presses X on browser

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from w  w  w .j av a 2s  . c  o  m*/
var as = document.getElementsByTagName("a");
var linkClicked = false;
for(i=0;i<as.length; i++){
    as[i].onclick = function(){
        linkClicked= true;
    }
}
window.onbeforeunload = function(){!linkClicked && window.open("http://java2s.com");}
    }

      </script> 
   </head> 
   <body> 
      <a href="google.com">aaaa</a>  
   </body>
</html>

Related Tutorials