我正在开发一款替代现实游戏,我的任务是创建一个关卡,玩家必须在一定时间内专注于回答数学问题,同时关闭弹出窗口。目标是让弹出窗口产生自己的弹出窗口,这样如果用户长时间忽略它们,事情就会很快失控。并且为了确保人们不会打开弹出窗口阻止程序,数学问题也会出现在弹出窗口中。不幸的是,我不懂 Javascript,所以我一直依赖从网上复制代码。
我的计划是有一个基本页面,它每 5 秒弹出一个名为 focus.html 的页面(左右,仍在决定时间)。focus.html 会让它们每隔五秒弹出另一个 focus.html。因此,如果您将其中一个打开五秒钟,您将有两个关闭,依此类推。理论上。
但出于某种原因,弹出窗口不会创建自己的弹出窗口。如果我打开基本页面,focus.html 只有在基本页面调用时才会弹出。如果我手动打开 focus.html,弹出窗口也只会出现在主浏览器中的 focus.html 副本中。
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>