URL为要开启的网页名字。
dialogArgments为设定好传递给新视窗网页的参数,可以为任意数据类型。
feature 与open()的类似,都是格式方面的设定。调用格式为featureName1:featureValue1:(分号)featureName2:featureValue2:
关于feature具体的参数我就不详细写了,看名字就应该知道什么用处了吧。
certer , dialogHeight, dialogLeft,dialogTop,dialogWidth,help(是否显示help按钮,下同),status,resizeable
值=1为yes,0为no.
我认为最重要的是dialogArgments,可以传递值到新的窗口。
第二重要就是 它的返回值 window.returnValue.可以在showModalDialog开启的窗口关闭后前,回传一个任意类型的值。
dialogArgments 可以传入一个变量,但是 我认为最好是传入一个window 这样的话,不光你可以调用你前面定义的变量names 和a 等等,还可以取到前一个页面上任何元素的值.如下面的代码所示:
alert(window.dialogArguments.names);
alert(window.dialogArguments.a );
// alert(window.dialogArguments.document.form1.t1.value)
window.dialogArguments.a = "Hello World"; //可以改变WebFromA里面的变量的值
window.dialogArguments.document.form1.t1.value = "t1";//可以修改WebFrom1里面的TextBox的value;
在WebFromB.aspx页面 我们可以取到 names 和a 的值还可以取到WebFromA的值.,还可以给它赋值.
整体的代码如下:
WebFromA.aspx
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server" >
< title > 无标题页 </ title >
< script language =javascript >
function fnA()
{
names = new Array(3);
names[0] = "chenzhifeng";
names[1] = "chenjiang";
a= "shuhui";
temp= window.showModalDialog("WebFormB.aspx",window);
// alert(a);
document.getElementById("t3").value = temp;
}
</ script >
</ head >
< body >
< form id ="form1" runat ="server" >
< div >
< input type =text value ="feng" id = "t1" />
< br />
< input type =text value ="chen" id = "t2" />
< input type =button value = "Click Me" onclick ="fnA();" id = "btn1" />
< p >
返回值: < input type = "text" id = "t3" />
</ div >
</ form >
</ body >
</ html >
WebFormB.aspx 如下:
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server" >
< title > 无标题页 </ title >
< script language =javascript >
// alert(window.dialogArguments.names);
alert(window.dialogArguments.a );
// alert(window.dialogArguments.document.form1.t1.value)
window.dialogArguments.a = "Hello World"; //可以改变WebFromA里面的变量的值
window.dialogArguments.document.form1.t1.value = "t1";//可以修改WebFrom1里面的TextBox的value;
</ script >
</ head >
< body >
< form id ="form1" runat ="server" >
< div >
< input type =text id = "tt" value = "Hello ZiFeng" />
< script language =javascript >
window.returnValue = document.getElementById("tt").value;
window.close();
</ script >
</ div >
</ form >
</ body >
</ html >
在WebFormB.aspx中 window.returnValue是用于 返回给WebFromA.aspx的值.
在WebFromA.aspx中,可以用一个变量来接收这个值 temp= window.showModalDialog("WebFormB.aspx",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。
参数传递:
要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象。
-------------------------------
例子:
共三个文件:
a.jsp 父窗口,可根据业务添加内容
showModalDialog.html 要显示的文档,不用更改
b.jsp 存放要显示数据的jsp,可以是Struts中*.do返回的页面。
a.jsp内容:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<body>
<html:form action="/contentAction.do?reqCode=savepost" method="post" styleId="form1">
<table>
<tr>
<td>
<input type="button" name="button" onClick="post()" value="分配">
</td>
</tr>
</table>
</html:form>
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
function post(){
var r=window.showModalDialog('showModalDialog.html','b.jsp','dialogheight=500px;dialogwidth=600px;status=0;center=yes;scroll=no;');
location.reload();
}
</SCRIPT>
b.jsp内容:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>客户反馈</title>
</head>
<body>
<html:form action="/contentAction.do?reqCode=savepost" method="post" styleId="form1">
<table>
<tr>
<td>
<input type="button" name="button" onClick="savepost()" value="保存">
</td>
</tr>
</table>
</html:form>
</body>
</html>
<script language="javascript">
function savepost(){
window.close()
}
</script>
showModalDialog.html内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>客户信息管理</title>
</head>
<body leftmargin="0" topmargin="0">
<iframe rameborder="0" width="100%" height="100%" name="mainFrame" id="mainFrame" style="display:none"></iframe>
</body>
</html>
<script language="JavaScript" type="text/javascript">
var a=window.dialogArguments;
window.mainFrame.location=a;
document.all.mainFrame.style.display="";
</script>