這個問題出在哪里
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ? var newwindow=confirm(新窗口打開網站);
? ? if(newwindow==yes)
? ? {
? ? // 新窗口打開時彈出確認框,是否打開
? ? var url=prompt("確定打開的網址");
? ? if(url!=null)
? ? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
? ? ? ? {windows.open('http;//www.xianlaiwan.cn/','_blank','width=400,height=500,toolbar=no,menubar=no');
? ? ? ? }
? ? else
? ? ? ? {alert("再見")};
? ? }
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ? else
? ? {alert("再見")};
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>
2019-05-18
head部分沒使用函數openWindow把代碼囊括,openWindow在body部分底部的onclick=的位置,openWindow可以隨便改,上下同步就行。
2019-05-12
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ? function openWindow(){
? ? var newwindow=confirm("打開網站嗎");
? ? if(newwindow){
? ? // 新窗口打開時彈出確認框,是否打開
? ? ? var url=prompt("確定打開的網址","http://www.xianlaiwan.cn/");
? ? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
? ? ? window.open(url,'_blank','width=400,height=500,toolbar=no,menubar=no');
? ? ?}
? ? ?else{
? ? ? ? ?alert("goodbye");}
? ? ?}
? ? }
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>
看起來沒什么區別了,為什么還是運行不了
2019-05-12
html里面引用的openWindow函數,所以腳本里要把所有代碼放在該函數里,不然不會引用
confir里面的參數是字符串,所以應該加雙引號,否則認為是變量
newwindow所得到的返回值是true或者false,不能用yes來比較
url的默認值沒有設置,也就是prompt的第二個參數沒有設置
windows.open里面的地址可以直接使用前面定義的url
附上源碼,如有疑問請聯系:
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ? function openWindow(){
? ? // 新窗口打開時彈出確認框,是否打開
? ? var sure=confirm("確定打開?");
? ? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
? ? if(sure){
? ? ? ? var url=prompt("輸入打開的網址","http://www.xianlaiwan.cn/");
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ? ? ? window.open(url,'_blank','width=400,height=500,menubar=no,toolbar=no')
? ? }
? ? }
? ? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>