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

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.


Search
I am...

Sajjad Hossain

I have five years of experience in web development sector. I love to do amazing projects and share my knowledge with all.

NEED HOSTING?
Are you searching for Good Quality hosting?
You can Try It!
Connect Social With PHPAns
Top