title: Auto close browser window
body: <p>I want to auto close a window in Firefox that is opened by a <strong>window.open()</strong> function. I have searched the Stack Overflow forum and found these links: </p>
  
  <p>1) <a href="https://stackoverflow.com/questions/14621554/how-to-close-automatically-a-webpage">How do I automatically close a webpage?</a>
  2) <a href="https://stackoverflow.com/questions/11487778/automatically-close-current-window-and-open-new-window-with-new-url-address">Automatically Close current window and open new window with new URL address</a></p>
  
  <p>But as I am not very much used to with JavaScript, I could not implement the code appropriately.</p>
  
  <p>Please find below the code which opens up a window - that needs to be auto closed. But inserting a  in the resulting html file makes it invalid.</p>
  
  <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt;
  function Clickheretoprint(vpid,vage,vroom,vname,vsex,vdoc,vdat)
  {
  
    var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
        disp_setting+="scrollbars=yes,width=300, height=200, left=100, top=25 resizable=yes";
    //var content_vlue = document.getElementById("T_PID").value;
  
  
     var docprint=window.open("","",disp_setting);
     docprint.document.open();
     docprint.document.write('&lt;html&gt;');
     docprint.document.write('&lt;body style="margin:0.01in 0.01in 0.01in 0.01in; width:3in;height:2in;position:absolute;" onLoad="self.print()"&gt;');
     docprint.document.write('&lt;table height="25%"&gt;');
  docprint.document.write('&lt;tr&gt;');
     docprint.document.write('&lt;td style=" font-weight: bold;" align="left"&gt;Regd : '+vpid+'&amp;nbsp;&amp;nbsp;&amp;nbsp;Date :'+vdat+'&lt;/td&gt;');
     docprint.document.write('&lt;/tr&gt;');
     docprint.document.write('&lt;tr&gt;');
     docprint.document.write('&lt;td style=" font-weight: bold;" align="left"&gt;Name : '+initCap(vname)+'&lt;/td&gt;');
     docprint.document.write('&lt;/tr&gt;');
     docprint.document.write('&lt;tr&gt;');
     docprint.document.write('&lt;td colspan=2 align="left"; &gt;&lt;B&gt;Age :&lt;/B&gt;'+vage+'&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;B&gt;Category :&lt;/B&gt;'+vsex+'&lt;/td&gt;');
     docprint.document.write('&lt;/tr&gt;');
     docprint.document.write('&lt;tr&gt;');
     docprint.document.write('&lt;td colspan=2 style="font-weight: bold;" &gt;'+vdoc+' &amp;nbsp;&amp;nbsp;&amp;nbsp;Room:'+vroom+'&lt;/td&gt;');
     docprint.document.write('&lt;/tr&gt;');
     docprint.document.write('&lt;/table&gt;');
     docprint.document.write('&lt;table height="25%"&gt;');
     docprint.document.write('&lt;tr&gt;&lt;td style="height:1in;width:100%;Font-family:CODE 39;"&gt; &lt;center&gt;');
     docprint.document.write('&lt;font face="CODE 39" size="7"&gt;');
     docprint.document.write('*'+vpid+'*');
  
     docprint.document.write('&lt;/font&gt;');
     docprint.document.write('&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt;');
     docprint.document.write('&lt;/table&gt;');
     docprint.document.write('&lt;/body&gt;&lt;/html&gt;');
     docprint.document.close();
     docprint.focus();
  }
  </code></pre>
  
  <p>Please let me know how to edit the resulting file so that it auto closes after 3 seconds.</p>
  
  <p>Thanks!</p>
  
  <p>PS: A little detailed answer will be appreciated as I am quite new to this field.</p>