我的老闆已經要求一個不會更改的頁面,以便有兩個定時彈出窗口加載。我找到了代碼並將其編輯爲我原先認爲應該執行的操作,但它只加載了最後一個onLoad事件。我是一名設計師,我幫助製作了網頁,但Javascript遠遠超出我所能理解的範圍。我已經學會了如何使用單彈出並花時間學習超時,但我似乎無法讓它使用多個彈出功能。如果你有時間,你會看看嗎?謝謝:)Javascript Pop Ups
^h
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>H's Page 1</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore, Editor -->
<!-- Web Site: The JavaScript Source -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
closetime = 3; // Close window after __ number of seconds?
// 0 = do not close, anything else = number of seconds
function Start1(URL, WIDTH, HEIGHT) {
windowprops = "left=50,top=50,width=" + WIDTH + ",height=" + HEIGHT;
preview = window.open(URL, "preview", windowprops);
if (closetime) setTimeout("preview.close();", closetime*1000);
}
function doPopup1() {
url = "http://www.google.com";
width = 1680; // width of window in pixels
height = 1050; // height of window in pixels
delay = 10; // time in seconds before popup opens
timer = setTimeout("Start1(url, width, height)", delay*1000);
}
closetime = 3; // Close window after __ number of seconds?
function Start2(URL, WIDTH, HEIGHT) {
windowprops = "left=50,top=50,width=" + WIDTH + ",height=" + HEIGHT;
preview = window.open(URL, "preview", windowprops);
if (closetime) setTimeout("preview.close();", closetime*1000);
}
function doPopup2() {
url = "http://www.yahoo.com";
width = 1680; // width of window in pixels
height = 1050; // height of window in pixels
delay = 5; // time in seconds before popup opens
timer = setTimeout("Start2(url, width, height)", delay*1000);
}
// End -->
</script>
<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->
<!-- Script Size: 1.27 KB -->
</head>
<body OnLoad="doPopup1(); doPopup2();">
<p>My page text.</p>
<p>My page text.</p>
<p>My page text.</p>
<p>My page text.</p>
</body>
</html>
您正在混合使用程序和功能樣式。例如,變量`closetime`在全局範圍內,應該只存在一次。在函數定義之前定義它,然後在另一個函數之前重新定義它,但它不會做你認爲它的工作。順便說一句,你應該引入`var`關鍵字的局部變量。我討厭這樣說,但我不得不建議獲得一本Javascript書。在StackOverflow答案中有太多內容需要覆蓋;寫Javascript,你必須知道Javascript! – 2011-01-07 02:22:15
感謝Tomalak。我將拿出第二個關閉時間。我很想了解更多,但這不是我有時間花時間學習代碼本身,希望我會有更多時間下一個項目。 – user566312 2011-01-07 02:43:01
我想知道您是否可以通過談判爲非設計工作獲得更多收入! – erjiang 2011-01-07 03:48:00