window.open用法

时间:2022-04-06 06:20:51

今天在慕课网上接触了下javaScript的基础。以下是结合运用了confirm(),prompt(),open()的小例子。

1. confirm(message);

    参数说明:

  message:在消息对话框中要显示的文本   返回值: Boolean值

返回值:

  当用户点击"确定"按钮时,返回true   当用户点击"取消"按钮时,返回false

2. prompt(text,defaultText);

    参数说明:

  text: 要显示在消息对话框中的文本,不可修改   defaultText:文本框中的内容,可以修改

    返回值:

  1. 点击确定按钮,文本框中的内容将作为函数返回值   2. 点击取消按钮,将返回null


3.window.open([URL], [窗口名称], [参数字符串])

window.open用法

1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>window.open</title> 6 <script type="text/javascript"> 7 function Wopen(){ 8 var whetherOpen = confirm("要不要去新世界?"); 9 if (whetherOpen == true) { 10 var url = prompt("输入您想去嘿嘿的网址"); //文本框中输入的内容返回存放在url中 11 window.open(url,‘_blank‘,‘width=600,height=400,top=100,left=0‘); //将url传入,选择新建窗口打开 12 }else{ 13 alert("不想去那你瞎点什么,滚!"); 14 } 15 } 16 </script> 17 </head> 18 <body> 19 <input type="button" value="别说话,先点我!" / > 20 </body> 21 </html>

注意:网址都要以开始

window.open用法

window.open用法

js——window.open用法