function openWindow()
{
var open=confirm("是否打开?");
{
if(open=true)
{
var url=prompt("确定打开吗?","http://www.imooc.com");
if(url!=null)
{
window.open('http://www.imooc.com','_blank','width=400,hight=500,menubar=0,toolbar=0');
}
else{alert("取消了");}
}
else{ alert("取消了")}
}
}
function openWindow(){
var msg=confirm("是否打开新窗口?");
if(msg=true)
{
var score=prompt("请输入网址","http://www.imooc.com");
if(score!=null && score!=""){
window.open('http://www.imooc.com','_blank','width=400px,height=500,menubar=no,toolbar=no');
}
}
else
{
return false
}
}
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>test</title> </head> <body> <button type="submit" id="btn">test</button> <script type="text/javascript" charset="utf-8"> var btn = document.getElementById("btn"); btn.onclick = function(){ var btnOpen = confirm("是否要打开一个网站?"); if (btnOpen==true){ var url = prompt("填入网址吧"); if(url!=null){ window.open(url) } else{alert("放弃了填写网址")} } else {alert("点了否")} }; </script> </body> </html>
取消倒数第二个else。你可以看看w3school的promt()