user3396187
user3396187

Reputation: 63

Popup window that auto closes in Javascript

I wanted to have an auto close feature for 5 seconds on my script, after 5 seconds the pop up window closes but since I researched about it,I didnt understand what the code said so I am here to ask how is the coding for it heres my code:

<script type="text/javascript">
function openWin()
{
    window.name = "_oldWindow";
    myBtn=window.open('','_NewWindow ','width=200,height=200');
    myBtn.document.write("<p>Lot Name: Esperanza</p>");
    myBtn.document.write("<p>Lot Price: P800,000</p>");
    myBtn.document.write("<p>Lot Size: 50 sq. metres</p>");
    myBtn.document.write('<a href="Admin/reserve.php"      target="_oldWindow">Reserve</a>');;
    myBtn.focus(); 
}
</script>

Upvotes: 1

Views: 85

Answers (1)

Sergio
Sergio

Reputation: 28837

Just add

setTimeout(function(){ myBtn.close()}, 5000);

as last line in your function. This will run the myBtn.close() method after a timeout of 5.000 miliseconds. 5 seconds x 1000 miliseconds.

Example with 5 second closing time: jsFiddle

Upvotes: 1

Related Questions