@barbara09
define the function popup() ← (simple answer)
extended answer:
a popup window is defined using the function window.open() (how to define the arguments, see
window.open – MDC).
after you have defined the popup() function, you can call it in setTimeout()
sample:
- function TimedPop()
-
{
-
// you variables and computations
-
var popup = function() {
-
window.open(...); // insert your values
-
}
-
var timer = window.setTimeout(popup, time);
-
}
-
-
window.onload = TimedPop;
this needs some explanation.
unless there is a good reason for it, you should declare all variables you use with the "var" keyword (not globally accessible).
line #10: instead of calling <body onload="..."> it is much more portable to call the onload in the script, so you don't need to put it in the HTML file (including the script does the job). the object "window" is so-to-speak representing the <body> for any event.
note that the function TimedPop() is in this case not called with parentheses!
line #4: a so-called "closure" (a more advanced javascript technique). the variable popup holds the function code defined in the curly brackets. the name "closure" derives from the fact, that any static variable value is preserved in it. you can call this function code like a normal function (i.e. popup()).
line #7: calling setTimeout(), there are two ways calling a function in setTimeout()
- insert the code to execute (in quotation marks)
- call the function name (without parentheses)
this is quite a lot of theory, but it will help you writing better javascript. If you have questions just ask.
regards