Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
120
rated 0 times [  124] [ 4]  / answers: 1 / hits: 44522  / 11 Years ago, wed, may 29, 2013, 12:00:00

I am making a web page, in which I have to open a popup window and it should remain open for a time period of 8 seconds(8000 ms).



After this time period that popup should be closed. Then again after 4 seconds I need to open same popup window for another 8 seconds.



I want to put some delay(4 seconds) before a popup open and closes automatically, and the popup window must be remain opened for 8 seconds



Here is my code:



<html>
<head>
<script>
function call()
{
popup = window.open('http://www.google.co.in');
setInterval(function() {wait();},4000);
}
function caller()
{
setInterval(function() {call();},5000);
}
function wait()
{
popup.close();
}
</script>
</head>
<body onload=caller();>
</body>
</html>


I am familiar with java script functions like setInterval() and setTimeout() but I've found none of them useful in this case.
I've also allowed my browser to open Popups, but this script opens a popup window and closes it as fast as time passes.
Please help me to find out the glitch in my code.



Thank you.


More From » html

 Answers
27

Your code is looking good in formatting but try to put some efforts on your code.

Try to use it as given below, Here is your whole code, I've tried it on my system, and it is working.



<html>
<head>
<script>
function call()
{
popup = window.open('http://www.google.co.in');
setTimeout(wait, 8000);
}
function caller()
{
setInterval(call, 12000);
}
function wait()
{
popup.close();
}
</script>
</head>
<body onload=caller();>
</body>
</html>

[#77951] Tuesday, May 28, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arthur

Total Points: 729
Total Questions: 107
Total Answers: 109

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;