【JS学习】慕课网2-7 练习题:制作新按钮,“新窗口打开网站” ,点击打开新窗口。

要求:

1、新窗口打开时弹出确认框,是否打开

提示: 使用 if 判断确认框是否点击了确定,如点击弹出输入对话框,否则没有任何操作。

2、通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/

3、打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。

 1 <!DOCTYPE html>
 2 <html>
 3  <head>
 4   <title> new document </title>  
 5   <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>   
 6   <script type="text/javascript">  
 7     
 8     // 新窗口打开时弹出确认框,是否打开
 9 
10     // 通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/
11 
12     //打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
13       function openWindow(){
14         var mymessage=confirm("open a website?");//confirm用法
15         if(mymessage==true)
16         { 
17            var open=prompt("please input a website name","http://www.imooc.com");//prompt对话框的用法
18        
19             window.open(open);
20         
21         }
22         else
23         {
24             document.write("null")
25         }
26     }
27     
28   </script> 
29  </head> 
30  <body> 
31       <input type="button" value="新窗口打开网站" onclick="openWindow()" /> 
32  </body>
33 </html>
原文地址:https://www.cnblogs.com/lijie33402/p/4380667.html