烜烜
2016-01-22 17:26
<!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.imooc.com");
}
else if(url != null){
window.open('http://www.imooc.com', '_blank','width=400px,height=500px,menubar=no,toolbar=no')
}
else if(page == false){
alert("byebye")
}
}
// 新窗口打开时弹出确认框,是否打开
// 通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/
//打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
你的if和第二个else if 不是同等地位的,你这样写,如果if的条件成立,就不会执行else if里面的语句了,所以要把那个对窗口的判断放在第一个if条件里面
也就是要改成
if(page == true){
var url = prompt("通过输入对话框,确定打开网站", "http://www.imooc.com");
if(url != null){
window.open(url, "_blank",'width=400px,height=500px,menubar=no,toolbar=no');
}
}
else{
alert("byebye");
}
不需要else if。楼上正解
if(page == true){
var url = prompt("通过输入对话框,确定打开网站", "http://www.imooc.com");
if(url != null){
window.open(url, "_blank",'width=400px,height=500px,menubar=no,toolbar=no')
}
}
else{
alert("byebye");
}改成这样
JavaScript入门篇
741590 学习 · 9869 问题
相似问题