I’m working on an alternate reality game, and I’m tasked with creating a level where player’s must focus on answering math questions within a certain amount of time while closing pop ups. The goal is to have the pop ups spawn their own pop ups, so that things quickly get out of control if the user ignores them for too long. And to ensure that people don’t leave their pop up blocker on, the math problems will be in pop ups too. Unfortunately, I don’t know Javascript, so I’ve been relying on copying code off the web.
My plan is to have a base page, which pops up a page called focus.html every 5 seconds (or so, still deciding on the time). focus.html will them, every five seconds, pop up another focus.html. So if you leave one open for five seconds, you’ll have two to close, and so on. In theory.
But for some reason, the pop ups don’t create their own pop ups. If I open the base page, focus.html only pops up when the base page calls for it. And if I open focus.html manually, the pop ups only occur from the copy of focus.html that is in the main browser as well.
The code for focus.html:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- <link rel="stylesheet" href="game.css" type="text/css" media="screen" /> -->
<title>Focus</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
closetime = 0; // Close window after __ number of seconds?
// 0 = do not close, anything else = number of seconds
function Start1(URL1, WIDTH, HEIGHT) {
windowprops = "left=50,top=50,width=" + WIDTH + ",height=" + HEIGHT;
preview = window.open(URL1, "preview", windowprops);
if (closetime) {
setTimeout("preview.close();", closetime*1000);
}
}
function doPopup1() {
url1 = "focus.html";
width = 500; // width of window in pixels
height = 500; // height of window in pixels
delay = 5; // time in seconds before popup opens
timer = setTimeout("Start1(url1, width, height)", delay*1000);
}
function doPopup2() {
url1 = "focus.html";
width = 500; // width of window in pixels
height = 500; // height of window in pixels
delay = 10; // time in seconds before popup opens
timer = setTimeout("Start1(url1, width, height)", delay*1000);
}
function doPopup3() {
url1 = "focus.html";
width = 500; // width of window in pixels
height = 500; // height of window in pixels
delay = 15; // time in seconds before popup opens
timer = setTimeout("Start1(url1, width, height)", delay*1000);
}
// End -->
</script>
</head>
<body OnLoad="doPopup1(); doPopup2(); doPopup3();">
<br />
<p>Remember to FOCUS.</p>
</body>
When the second window is opened, it will have the same name as the first, so you will never be able to open more than one. If you do not pass a name (empty string) you will be able to open many.