window.open() 父子页面的传参&传值问题

window.open() 传参问题:
父页面中:
window.open('url', '', 'resizable=1, menuBar=0, toolBar=0, scrollbars=yes, Status=yes, resizable=1');


url页面拿父页面的xx元素赋值
opener.document.getElementById("xx").value="newValue";


if(window.opener){//判断是否有父窗口,即打开本页面的窗口
window.opener.location.reload();//刷新父窗口
window.opener.close(); //关闭父窗口
}



[b]window.open() 传值问题(参考:http://www.cnblogs.com/gavindou/archive/2008/04/09/1143858.html):[/b]
a.html(父)
注意:window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no"); 中的第3个参数一定要有 [b]modal=yes[/b]
<!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=document.getElementById("color").value;
oOption.value=document.getElementById("color").value;
//检查浏览器类型
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" id="color" value="填写颜色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="确认" onclick="ClickOk();" /> </td>
</tr>
</form>
</table>
</body>
</html>



var url = '/xxx/xx.jsp?yearNum='+yearNum;

if (typeof window.ActiveXObject != 'undefined') { // 支持IE浏览器
var weekNum=document.getElementById("weekNum").value;
var arguments = new Array();
arguments[0] = weekNum;
var returnValue = window.showModalDialog(url,arguments,'dialogHeight:500px;dialogWidth:380px;dialogTop:300px; dialogLeft:500px;center:yes;scroll:yes;status:no;resizable:no;edge:raised;help:no;unadorned:yes');
if(returnValue!=null && returnValue[0]){
document.getElementById("weekNum").value=returnValue[1];
document.getElementById("beginDate").value=returnValue[2];
document.getElementById("endDate").value=returnValue[3];
}
}
else if((typeof document.implementation != 'undefined')
&&(typeof document.implementation.createDocument!='undefined')) { // 支持Mozilla浏览器

window.open(url,'weekNum','modal=yes,menubar=0,status=0,toolbar=0,scrollbars=1,resizable=1,width=400px,height=500px,top=300,left=500');

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值