JavaScript close window automatically after 10 seconds

  • Author: Sajjad Hossain
  • |
  • Added: Jul 23, 2017
  • |
  • In: Javascript

I am working on a project "Accounts & Inventory Management System" Here needs a javascript auto close window after 10 seconds. I used javascript for this and simply complete this. This is working like this.

> When opening a window with a notice. like , 

Please select a seller to process the report. 

This window will close automatically within 10 second(s)

> Count down every second like- 10,9,8,7,6,5,4,3,2,1 and close the window automatically.

If you searching this type of solution then here is the javascript code for it.

<p style="text-align:center">Please select a seller to process the report.<br/>This window will close automatically within <span id="counter">10</span> second(s).</p>

<script type="text/javascript">

function countdown() {

    var i = document.getElementById('counter');

    i.innerHTML = parseInt(i.innerHTML)-1;

if (parseInt(i.innerHTML)<=0) {




setInterval(function(){ countdown(); },1000);


Hope this will solve your problem and help you in your need. If JavaScript close window automatically after 10 seconds article is helpful for you then spread out by sharing, Thank you.

Meet with owner

Sajjad Hossain

Hey, I am Sajjad, working in web development sector since 2012. I love to do amazing things. Let's do a project together.
Connect Social With PHPAns