title: Javascript window.close() function
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function validateLoginForm(){
    var str = '';
    if(trim(document.getElementById('userName').value)=='')
     str = 'UserName is Required\r\n';
    if(trim(document.getElementById('password').value)=='')
     str = str+'Password is Required';
    if(str=='')
     return true;
    else{
     alert(str);
     return false; 
    }
     }
      
   function myOpenWindow() {
     var rand_no = Math.round(1000*Math.random());
    
     if(window.name == "IMSWindowName"){
        windowName = "IMSWindowNameFirst"+rand_no;
         windowName = "_self"+rand_no;
     }else{
        windowName = "IMSWindowName"+rand_no;
         windowName = "_self"+rand_no;
     }
     heightVal=screen.height-150;
     widthVal=screen.width-150;
    
     newwin2 = window.open('',windowName,'toolbar=no,status=0,resizable=1,scrollbars=1,top=0,left=0,height='+heightVal+',width='+widthVal+'');
     document.forms[0].target=windowName;
     document.forms[0].action='LogIn';
     document.forms[0].method='post';
     newwin2.focus();
     window.opener='X'; 
     window.open('','_parent',''); 
     window.close();
     }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type=submit class="myButton" value="Sign In" title="Ok" onClick="if(validateLoginForm()){myOpenWindow();quitBox('quit');}else{return false;}"/&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=button class="myButton" value="Clear" title="Reset" onClick="document.forms[0].reset();"/&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I tried this code to automatically close the login window when it is logged in. This code works perfectly with IE browsers but failed to work in other browsers like chrome and firefox? </p>