分享

javascript实战演练,制作新按钮,‘新窗口打开网站’,点击打开新窗

 怡红公子0526 2021-11-14

通过练习javascript中的document.write()输出展示;消息弹出框alert(字符串或变量);消息对话框confirm(str);用户交互的信息prompt(str1, str2);打开新窗口window.open([URL], [窗口名称], [参数字符串]);window.close();//关闭本窗口或者是<窗口对象>.close();//关闭指定的窗口的学习,下面根据要求测试:

要求:

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

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

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

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

个人代码展示:

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>编程练习挑战</title>
 6         <script type="text/javascript">
 7         function rec(){
 8             // var ceshi=confirm("新窗口打开时弹出确认框,是否打开")
 9             var ceshi=prompt('新窗口打开时弹出确认框,是否打开','https://www.cnblogs.com/dhnblog/');
10             if(ceshi!=null){
11                 window.open('https://www.cnblogs.com/dhnblog/','_blank','width=400px,height=500px,menubar=no,toolbar=no')
12             }
13             else{
14                 document.write('haode')
15             }
16         }
17         </script>
18     </head>
19     <body>
20         <input type="button" name="" id="" value="新窗口打开网站" onclick="rec()"/>
21     </body>
22 </html>

 正确代码展示:

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>浏览器对象</title>
 6         <script type="text/javascript">
 7             function ceshi(){
 8                 if(confirm('确定打开新窗口吗'))
 9                 {
10                     var url=prompt('请输入一个网址','https://www.baidu.com/');
11                     window.onpen(url,'_blank','toolbar=no,menubar=no,scrollbars=yes,width=400,height=400');
12                 }
13             }
14         </script>
15     </head>
16     <body>
17         <input type="button" name="" id="" value="新窗口打开网站" onclick="ceshi()" />
18     </body>
19 </html>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多