我正在研究一种替代的现实游戏,我的任务是创建一个关卡,玩家必须专注于在关闭弹出窗口的同时在一定时间内回答数学问题。目标是让弹出窗口产生他们自己的弹出窗口,这样如果用户长时间忽略它们,事情很快就会失控。为了确保人们不会让他们的弹出窗口阻止,数学问题也会出现在弹出窗口中。不幸的是,我不知道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>
答案 0 :(得分:1)
preview = window.open(URL1, "preview", windowprops);
当第二个窗口打开时,它将与第一个窗口具有相同的名称,因此您将永远无法打开多个窗口。如果您没有传递名称(空字符串),您将能够打开许多名称。