<!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 mywin=confirm("是否打开一个新窗口")
if (mywin==ture){
var web=prompt("请输入你要打开的网址","http://www.imooc.com")
if web==null{
web.open("_blank","width:400px","heigh:500px","menubar=no","toolbar=no"
}
}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
if语句有问题,打开窗口的命令window.open();
正确代码如下: <!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 mywin = confirm("是否打开一个新窗口"); if (mywin==true){ var web=prompt("请输入你要打开的网址","http://www.imooc.com"); if (web != null){ window.open(web,"_blank","width=400px,heigh=500,menubar=no,toolbar=no"); } } } </script> </head> <body> <input type="button" value="新窗口打开网站" onclick="openWindow()" /> </body> </html>
if(web!=null){
}
if web==null{ // 是不是应该改成
if web!=null{