通過練習(xí)javascript中的document.write()輸出展示;消息彈出框alert(字符串或變量);消息對話框confirm(str);用戶交互的信息prompt(str1, str2);打開新窗口window.open([URL], [窗口名稱], [參數(shù)字符串]);window.close();//關(guān)閉本窗口或者是<窗口對象>.close();//關(guān)閉指定的窗口的學(xué)習(xí),下面根據(jù)要求測試: 要求:1、新窗口打開時(shí)彈出確認(rèn)框,是否打開
2、通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 https://www.cnblogs.com/dhnblog/ 3、打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。 個人代碼展示: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>編程練習(xí)挑戰(zhàn)</title> 6 <script type="text/javascript"> 7 function rec(){ 8 // var ceshi=confirm("新窗口打開時(shí)彈出確認(rèn)框,是否打開") 9 var ceshi=prompt('新窗口打開時(shí)彈出確認(rèn)框,是否打開','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="新窗口打開網(wǎng)站" 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('請輸入一個網(wǎng)址','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="新窗口打開網(wǎng)站" onclick="ceshi()" /> 18 </body> 19 </html> |
|