 
		陪君醉笑三千场
2016-03-16 10:25
<html>
 <head>
  <title> new document </title>  
  <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>   
  <script type="text/javascript">
  function openWindow(){
      var message=confirm("是否要打开一个新网页?");
      if(message==true){
          var website=prompt("请输入网站地址:","http://www.imooc.com/");
          if(website!=null){
              window.open('website','_blank','width=400,height=500,top=0,left=0,menubar=no,toolbar=no,scrollbars=yes,status=yes');
          }
          else{
              alert("再见吧朋友");
          }
      }
      else{
          alert("再见吧孩子");
      } 
  }
  openWindow();
  </script> 
 </head> 
 <body> 
      <input type="button" value="新窗口打开网站" onclick="openWindow()" /> 
 </body>
</html>
运行不了,有大神能帮忙指出错误吗?
 
				第一: window.open('website','_blank','width=400,height=500,top=0,left=0,menubar=no,toolbar=no,scrollbars=yes,status=yes');
website的单引号应该去掉。
第二: openWindow();
  </script> 
这里不需要再调用openWindow()了,函数是通过点击触发的。不用再调用
第三:这节练习不验证代码,你把代码保存成.html 直接在浏览器就可以运行了。不需要依赖这里的环境
 
				window.open('website',
这里website是变量,不需要添加''包括。
 
				window.open('website','_blank','width=400,height=500,top=0,left=0,menubar=no,toolbar=no,scrollbars=yes,status=yes');
这里website是变量,不需要添加''包括。
JavaScript入门篇
741613 学习 · 9869 问题
相似问题