我正在製作一個備用現實遊戲,我的任務是創建一個關卡,玩家必須專注於在關閉彈出窗口的同時在一段時間內回答數學問題。目標是讓彈出窗口產生他們自己的彈出窗口,這樣如果用戶忽略它們太久,事情就會很快失去控制。爲了確保人們不會讓他們的彈出窗口阻擋,數學問題也將出現在彈出窗口中。不幸的是,我不知道Javascript,所以我一直依靠從網上覆制代碼。我該如何創建一個彈出窗口來創建其他彈出窗口?
我的計劃是有一個基本頁面,每5秒鐘彈出一個名爲focus.html的頁面(或者仍然決定時間)。 focus.html會每5秒鐘彈出一個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>
瀏覽器只會打開一個特定頁面的任何給定名稱的彈出窗口,所以傳遞''preview''作爲'window.open()'的第二個參數會導致您的問題。改爲傳遞'undefined'。 –
不要將字符串傳遞給'setTimeout',它使用'eval'。傳遞函數:'setTimeout(function(){Start1(url1,width,height);},delay * 1000)' –
謝謝,它工作完美。 – CowGoes