<!DOCTYPE?html>
<html>
?<head>
??<title>?new?document?</title>??
??<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"/>???
??<script?type="text/javascript">?
????function?openWindow(){
????var?page?=?confirm("新窗口打開網站");
???? if(page?==?true){
???? var?url?=?prompt("通過輸入對話框,確定打開網站",?"http://www.xianlaiwan.cn");
???? }
???? else?if(url?!=?null){
???? window.open('http://www.xianlaiwan.cn',?'_blank','width=400px,height=500px,menubar=no,toolbar=no')
???? }
???? else?if(page?==?false){
???? alert("byebye")
???? }
????}
????//?新窗口打開時彈出確認框,是否打開
????//?通過輸入對話框,確定打開的網址,默認為?http://www.xianlaiwan.cn/
????//打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
????
????
??</script>?
?</head>?
?<body>?
??<input?type="button"?value="新窗口打開網站"?onclick="openWindow()"?/>?
?</body>
</html>
2016-01-22
你的if和第二個else if 不是同等地位的,你這樣寫,如果if的條件成立,就不會執行else if里面的語句了,所以要把那個對窗口的判斷放在第一個if條件里面
也就是要改成
? ?if(page?==?true){
????????????var?url?=?prompt("通過輸入對話框,確定打開網站",?"http://www.xianlaiwan.cn");
????????????if(url?!=?null){
????????????????window.open(url,?"_blank",'width=400px,height=500px,menubar=no,toolbar=no');
????????????}
????????}
????????else{
????????????alert("byebye");
????????}
2016-01-22
不需要else if。樓上正解
2016-01-22
改成這樣