JavaScript close window automatically after 10 seconds

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) {

window.close();

}

}

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

</script>

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.

Sajjad Hossain
Hi, I'm Sajjad Hossain, a PHP Developer working on PHP Development since 2012. If you have a project that you want to start you can contact me. I'm currently available for freelance work. Ping me on Facebook, Messenger, WhatsApp or Email.

We use cookies on our website. To find out more about how and why they are used or opt-out, please read our Cookie Policy. By choosing "I Accept", you consent to our use of cookies. Cookie Policy