时间:2021-07-01 10:21:17 帮助过:46人阅读
<script type="text/javascript">
var obj = new Object();
obj.name="51js";
window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
modal.htm
代码如下:
<script type="text/javascript">
var obj = window.dialogArguments
alert("您传递的参数为:" + obj.name)
</script>
-------------------------------
2.可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:
------------------------------
parent.htm
代码如下:
< type="text/java">
str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>
modal.htm
代码如下:
<script type="text/javascript">
window.returnValue="//www.gxlcms.com";
</script>
在IE中,我们可以使用showModalDialog来传值。
语法如下:
vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
但是.在Firefox中却沒有showModalDialog方法,不过我们可以用window.open()
语法如下:
oNewWindow = window.open( [sURL] [, sName] [, sFeatures] [, bReplace])
只是,在Firefox下,window.open的参数中,sFeature多了一些功能设定,而在FireFox下要让开启的视窗跟IE的showModalDialog一样的话,只要在sFeatures中加個modal=yes就可以了。
下面用一个示例来说明其用法。
功能说明:从子窗口中输入颜色种类提交到父窗口,并添加选项到下拉列表。
a.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>a.html文档</title>
<script language="javascript">
function openstr()
{
ReturnValue=window.showModalDialog("b.html",window,"dialogWidth=510px;dialogHeight=150px;status=no");
if(ReturnValue && ReturnValue!="")
{
oOption = document.createElement('OPTION');
oOption.text=ReturnValue;
oOption.value=ReturnValue;
document.all.txtselect.add(oOption);
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="txtselect" id="txtselect">
</select>
</label>
<label>
<input type="button" name="Submit" value="打开子窗口" onclick="openstr()" />
</label>
</form>
</body>
</html>
b.html
代码如下:
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>b.html文档</title>
<script language="javascript">
function ClickOk()
{
var t=document.Edit;
var url=t.color.value;
if(url==null||url=="填写颜色") return(false);
window.returnValue=url;
window.close();
}
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
<form name="Edit" id="Edit">
<tr>
<td width="30" align="right" height="30">color:</td>
<td height="30"><input type="text" name="color" value="填写颜色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="确认" onclick="ClickOk();" /> </td>
</tr>
</form>
</table>
</body>
</html>
修改为兼容IE和FireFoxr的代码如下:
[code]
<!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>a.html文档</title>
<script type="text/javascript">
function openstr()
{
window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no");
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="txtselect" id="txtselect">
</select>
</label>
<label>
<input type="button" name="Submit" value="打开子窗口" onclick="openstr()" />
</label>
</form>
</body>
</html>
b.html
代码如下:
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>b.html文档</title>
<script type="text/javascript">
function ClickOk()
{
var t=document.Edit;
var color=t.color.value;
if(color==null||color=="填写颜色") return(false);
var oOption = window.opener.document.createElement('OPTION');
oOption.text=url;
oOption.value=url;
//检查浏览器类型
var bname = navigator.appName;
if (bname.search(/netscape/i) == 0)
{
window.opener.document.getElementById("txtselect").appendChild(oOption);
}
else if (bname.search(/microsoft/i) == 0)
{
window.opener.document.all.txtselect.add(oOption);
}
else
{
}
window.close();
}
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
<form name="Edit" id="Edit">
<tr>
<td width="30" align="right" height="30">color:</td>
<td height="30"><input type="text" name="color" value="填写颜色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="确认" onclick="ClickOk();" /> </td>
</tr>
</form>
</table>
</body>
</html>
12下一页阅读全文