一、window.open()支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+

 

两者区别:

 

window.open()是打开一个新窗口,因此可以读原来的窗口(父窗口)进行操作,并且有window.opener对象..

 

window.showModalDialog()是打开一个遮罩层的子窗口,子窗口存在时不能对父窗口进行操作,不能使用window.opener对象..

二、基本语法:
window.open(pageURL,name,parameters)
其中:
pageURL 为子窗口路径
name 为子窗口句柄
parameters 为窗口参数(各参数用逗号分隔)


三、示例:

<SCRIPT> 
<!-- 
window.open ('page.html','newwindow','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no') 
//写成一行 
--> 
</SCRIPT>
脚本运行后,page.html将在新窗体newwindow中打开,宽为100,高为400,距屏顶0象素,屏左0象素,无工具条,无菜单条,无滚动条,不可调整大小,无地址栏,无状态栏。
请对照。



上例中涉及的为常用的几个参数,除此以外还有很多其他参数,请见四。


四、各项参数
其中yes/no也可使用1/0;pixel value为具体的数值,单位象素。

参数 | 取值范围 | 说明
| |
alwaysLowered | yes/no | 指定窗口隐藏在所有窗口之后
alwaysRaised | yes/no | 指定窗口悬浮在所有窗口之上
depended | yes/no | 是否和父窗口同时关闭
directories | yes/no | Nav2和3的目录栏是否可见
height | pixel value | 窗口高度
hotkeys | yes/no | 在没菜单栏的窗口中设安全退出热键
innerHeight | pixel value | 窗口中文档的像素高度
innerWidth | pixel value | 窗口中文档的像素宽度
location | yes/no | 位置栏是否可见
menubar | yes/no | 菜单栏是否可见
outerHeight | pixel value | 设定窗口(包括装饰边框)的像素高度
outerWidth | pixel value | 设定窗口(包括装饰边框)的像素宽度
resizable | yes/no | 窗口大小是否可调整
screenX | pixel value | 窗口距屏幕左边界的像素长度
screenY | pixel value | 窗口距屏幕上边界的像素长度
scrollbars | yes/no | 窗口是否可有滚动栏
titlebar | yes/no | 窗口题目栏是否可见
toolbar | yes/no | 窗口工具栏是否可见
Width | pixel value | 窗口的像素宽度
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上

window.showModalDialog使用手册


基本介绍:

showModalDialog() (IE 4+ 支持)
showModelessDialog() (IE 5+ 支持)
window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框。
window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框。

使用方法:
vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])



参数说明:
sURL--
必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
vArguments--
可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。
sFeatures--
可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。
1.dialogHeight :对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。
2.dialogWidth: 对话框宽度。
3.dialogLeft: 离屏幕左的距离。
4.dialogTop: 离屏幕上的距离。
5.center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。
6.help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。
7.resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。
8.status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
9.scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。
下面几个属性是用在HTA中的,在一般的网页中一般不使用。
10.dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。
11.edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。
12.unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。

参数传递:
1.要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,例如:
-------------------------------

parent.htm
<script>
var obj = new Object();
obj.name="51js";
window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
modal.htm
<script>
var obj = window.dialogArguments
alert("您传递的参数为:" + obj.name)
</script>


-------------------------------
2.可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:
------------------------------

parent.htm
<script>
str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>
modal.htm
<script>
window.returnValue="http://www.51js.com";
</script>

币种定义部分 

var psAddStr="ProcessID="+ProcessID+"&AddFlag="+isAddFlag+"&BZBH="+vsBZBH+"&BZMC="+vsBZMC+"&BZFH="+vsBZFH+"&JD="+vsJD;

var Result=window.showModalDialog("addSave.asp?"+psAddStr,'',"dialogHeight:250px;dialogWidth:250px;status:no;");

 

window.showModalDialog 和 window.open
有什么区别 



window.open 
('page.html','','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, 
resizable=no,location=no, status=no'); 
            var getv = 
window.showModalDialog("log.htm", "", "dialogWidth:420px; 
dialogHeight:220px;status:no;help:yes"); 
window.open是打开新窗口 

window.showModalDialog(URL,dialogArgments.features) 
打开一个新窗口 
URL为要开启的网页。 

dialogArgments为设定好传递给新视窗网页的参数,可以为任意数据类型。 

feature 
与open()的类似,都是格式方面的设定。调用格式为featureName1:featureValue1:(分号)featureName2:featureValue2: 
certer , dialogHeight, 
dialogLeft,dialogTop,dialogWidth,help(是否显示help按钮,下同),status,resizeable 
值=1为yes,0为no. 

我认为最重要的是dialogArgments,可以传递值到新的窗口。 

第二重要就是 它的返回值 
window.returnValue.可以在showModalDialog开启的窗口关闭后前,回传一个任意类型的值
showModalDialog帮助可以参阅微软MSDN http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/showmodaldialog.asp 

AA.HTM 

-------------------------------------------------------------------------------------------------------------------------- 

<html>

<head> 

<meta http-equiv="Content-Type" 
content="text/html; charset=gb2312"> 
<title>主界面</title> 

</head>

<body> 

<form id="getForm">    回传值:<input 
type="text" id="getData" readOnly> <input type="text" id="getData1" 
readOnly>
</form> 

<input type="button" value="打开新窗口1" 
onClick="openWin1()"> 
<input type="button" value="打开新窗口2" 
onClick="openWin2()"> 
<script language="JavaScript">    

function openWin1()    

{        

var srcFile = "BB.htm";    //新窗口的文档名称        

var winFeatures = "dialogHeight:300px; 
dialogLeft:200px;";        
var obj = getForm; //将form作为对象传递给新窗口               

window.showModalDialog(srcFile, obj, 
winFeatures);    
} 

function openWin2()    

{        

var srcFile = "CC.htm";    //新窗口的文档名称        

var winFeatures = "dialogHeight:300px; 
dialogLeft:200px;";        
var obj = getForm.getData.value; 
//将form作为对象传递给新窗口               
var str=window.showModalDialog(srcFile, obj, 
winFeatures);    
if(str!=null) 

     document.getForm.getData.value = str; 

} 

</script>

</body>

</html> 

BB.HTM 

重要提示:你弹出窗口中调用的是ASPX文件时,必须在Page_Load事件中加入以下代码 

Response.Expires = 0; Response.Cache.SetNoStore(); 
Response.AppendHeader("Pragma", "no-cache"); 
否则,每次弹出的页面都是上一次的Cache,不会改变。 

------------------------------------------------------------------------------------------------------------------------ 

<html>

<head> 

<meta http-equiv="Content-Type" 
content="text/html; charset=gb2312"> 
<title>新窗口BB</title> 

</head>

<base target="_self"> 
<!--这句话非常重要,只要加上才能保证在弹出窗口中调用服务端代码而不会再弹出一个新窗口--> 
<body> 

<form id="sendForm">    请输入资料: 

<input type="text" id="writeData">    

<input type="text" id="writeData1"> 

<input type="button" value="送回父窗口" 
onClick="send(sendForm.writeData.value,sendForm.writeData1.value);"> 
</form> 

<script language="JavaScript">    

function send(val,val1)    

{        

    //取得父窗口传过来的对象        

    var myObj = window.dialogArguments;        

    //赋值 

    myObj.getData.value = val; 

    myObj.getData1.value = val1; 

    //关闭窗口        

    window.close();    

} 

</script>

</body>

</html> 

CC.HTM 

------------------------------------------------------------------------------------------------------------------------ 

<html>

<head> 

<meta http-equiv="Content-Type" 
content="text/html; charset=gb2312"> 
<title>新窗口CC</title> 

</head>

<base target="_self"> 
<!--这句话非常重要,只要加上才能保证在弹出窗口中调用服务端代码而不会再弹出一个新窗口--> 
<body> 

<form id="sendForm">    请输入资料: 

<input type="text" id="writeData">    

<input type="button" value="送回父窗口" 
onClick="send(sendForm.writeData.value);"> 
</form> 

<script language="JavaScript">    

function send(val)    

{         

    window.returnValue=val 

    window.close();    

} 

</script>

</body>

</html>

 

 

 

window窗体对象open()和showModalDialog()用法

js窗口&提示大全

问:如何利用Ext在弹出窗口中调用另外一个页面

1.模式对话框父窗口 弹出模式对话框 代码如下



Java代码

OpenAIEmbeddings 使用其他模型_父窗口

OpenAIEmbeddings 使用其他模型_html_02

OpenAIEmbeddings 使用其他模型_html_03


    1. window.showModalDialog(url,window,   
    2.   
    3. "help:no;scroll:no;resizable:no;status:0;dialogWidth:420px;dialogHeight:200px;center:yes" );
    window.showModalDialog(url,window, 
    
    "help:no;scroll:no;resizable:no;status:0;dialogWidth:420px;dialogHeight:200px;center:yes" );


    1.

    参数1 url,url后面可以接"?name=user"参数

    参数2 传递给子窗口的值 可以是window对象,数组 var arry=[],其他变量 类型不限制,对于字符串类型,最大为4096个字符。也


    可以传递对象


    参数3 设置子窗口的高度 ,宽度 等元素

    dialogHeight :对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便


    其见,在定义modal方式的对话框时,用px做单位。

    dialogWidth: 对话框宽度。

    dialogLeft: 离屏幕左的距离。

    dialogTop: 离屏幕上的距离。

    center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。

    help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。

    resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。

    status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。

    scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。

    下面几个属性是用在HTA中的,在一般的网页中一般不使用。

    dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。

    edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。

    unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。



    2.子父窗口传值


    在子窗口获取 父窗口的值

    var param = window.dialogArguments  //获取传递的参数


    如果是 数组或字符串对象 可以在子窗口进行相应操作,例如把该值赋给子窗口的某个元素等等


    如果传递的是 父窗口对象 可以通过 param .document.getElementById('checkAllid2'); 获取父窗口的

    html 元素进行相应的操作


    3.模式对话框提交

    模式对话框如果有form需要提交,提交时会新开一个浏览器,所以模式对话框提交时需要提交到

    fream框架页面 在form元素中加上target="mainFrame"




    Java代码

    OpenAIEmbeddings 使用其他模型_html_04

    OpenAIEmbeddings 使用其他模型_新窗口_05

    OpenAIEmbeddings 使用其他模型_html_06

    1. <form id="myFrom" action="submit.jsp?checkResult=failure" method="post" target="mainFrame">  
    2.  </form>
    <form id="myFrom" action="submit.jsp?checkResult=failure" method="post" target="mainFrame">
        </form>



    target="mainFrame" 是主页面的 中间框架的id


    主页面



    Java代码

    OpenAIEmbeddings 使用其他模型_父窗口_07

    OpenAIEmbeddings 使用其他模型_新窗口_08

    OpenAIEmbeddings 使用其他模型_新窗口_09


      1. <frameset id="middleframe" rows="95,8,*,30" cols="*"  framespacing="0">  
      2. "bannar.jsp" name="topFrame" scrolling="NO" noresize border=0  frameborder=0>  
      3. "scollbar.htm" name="ScollbarFrame" scrolling="NO" noresize border=0  frameborder=0 >  
      4. "bodyFrame" rows="*" cols="230,8,*" framespacing="0"  border="0" >  
      5. "menu.jsp" name="leftFrame"  scrolling="no" noresize border=0  frameborder=0>  
      6. "Scoll.htm" name="ScollFrame" scrolling="NO" noresize border=0  frameborder=0>  
      7. "main_tab.jsp" name="mainFrame" id="mainFrame" scrolling="auto"  border=0  frameborder=0><!--   
      8.   
      9. main/main_tab.html -->  
      10.   </frameset>  
      11. "bottom.jsp" scrolling="NO"  name="bottomFrame" id="bar" border=0  frameborder=0>  
      12. </frameset>
      <frameset id="middleframe" rows="95,8,*,30" cols="*"  framespacing="0">
        <frame src="bannar.jsp" name="topFrame" scrolling="NO" noresize border=0  frameborder=0>
         <frame src="scollbar.htm" name="ScollbarFrame" scrolling="NO" noresize border=0  frameborder=0 >
        <frameset id="bodyFrame" rows="*" cols="230,8,*" framespacing="0"  border="0" >
          <frame src="menu.jsp" name="leftFrame"  scrolling="no" noresize border=0  frameborder=0>
      	<frame src="Scoll.htm" name="ScollFrame" scrolling="NO" noresize border=0  frameborder=0>
          <frame src="main_tab.jsp" name="mainFrame" id="mainFrame" scrolling="auto"  border=0  frameborder=0><!-- 
      
      main/main_tab.html -->
        </frameset>
        <frame src="bottom.jsp" scrolling="NO"  name="bottomFrame" id="bar" border=0  frameborder=0>
      </frameset>



      4.可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例



      Java代码

      OpenAIEmbeddings 使用其他模型_html_10

      OpenAIEmbeddings 使用其他模型_html_11

      OpenAIEmbeddings 使用其他模型_新窗口_12

      1. parent.htm   
      2. <script>   
      3. str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");   
      4. alert(str);   
      5. </script>   
      6. modal.htm   
      7. <script>   
      8. window.returnValue="http://www.web3.cn";   
      9. </script>


      parent.htm 
      <script> 
      str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px"); 
      alert(str); 
      </script> 
      modal.htm 
      <script> 
      window.returnValue="http://www.web3.cn"; 
      </script>


      2.window.open

      window.open打开窗口时 可以打开多个 且焦点不会锁定在子窗口,仍然能够操作父窗口。这样的特点使得某些情况下

      我们最好不要用open打去开一个子窗口

      父窗口打开子窗口代码



      Java代码

      OpenAIEmbeddings 使用其他模型_新窗口_13

      OpenAIEmbeddings 使用其他模型_新窗口_14

      OpenAIEmbeddings 使用其他模型_新窗口_15


        1. window.open(url, "","help=no,toolbar=no,height=330,width=515,top=50,left=50,resizable=no,status=no,toolbar=no,menubar=no,directories ,titlebar=no,location=no");
        window.open(url, "","help=no,toolbar=no,height=330,width=515,top=50,left=50,resizable=no,status=no,toolbar=no,menubar=no,directories ,titlebar=no,location=no");


        参数1.url,url后面可以接"?name=user"

        参数2.弹出窗口的名字(非文件名) 可以为空

        参数3.设置子窗口的高度 ,宽度 等属性


            height=100 窗口高度; 

          width=400 窗口宽度; 

          top=0 窗口距离屏幕上方的象素值; 

          left=0 窗口距离屏幕左侧的象素值; 

          toolbar=no 是否显示工具栏,yes为显示; 

          menubar,scrollbars 表示菜单栏和滚动栏。 

          resizable=no 是否允许改变窗口大小,yes为允许; 

          location=no 是否显示地址栏,yes为允许; 

          status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;