Open link in new window and focus - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window open

Description

Open link in new window and focus

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function openWin(doFocus)/*  w  ww.j  ava  2 s  .  c  o m*/
{
    myWindow=window.open('','mywindow');
    myWindow.document.write("<p>This is 'myWindow'</p>");
    if(doFocus){
        myWindow.focus();
    }
    
}

      </script> 
   </head> 
   <body> 
      <input type="button" value="Open window, focus" onclick="openWin(true)"> 
      <input type="button" value="Open window, nofocus" onclick="openWin()">  
   </body>
</html>

Related Tutorials