js实现在父窗口打开子窗口,子窗口获取父窗口数据,
格式:window.showModalDialog(url,window,'dialogwidth=1800px;dialogheight=350px;status:yes;titlebar:no;toolbar:no;scrollbars:yes;resizable:yes;center:yes');
实例描述:在主表单中,嵌入一个iframe,通过iframe里面的按钮打开子窗口,在子窗口中获取主表单数据
例如:window.showModalDialog(
‘index.jsp?id=’+id,
window,
'dialogwidth=1800px;dialogheight=350px;status:yes;titlebar:no;toolbar:no;scrollbars:yes;resizable:yes;center:yes');
在子窗口中,获取父窗口的对象以及数据:子窗口的上一级父窗口为iframe,而主表单为上两级窗口,所以要用到parent
var parentObj = window.dialogArguments; //传递的window就代表父窗口对象
var val = parentObj .parent.document.getElementById("id").value;
如果只有一级:var val = parentObj .document.getElementById("id").value;
parentObj.document.location.href= parentObj.document.location.href; //刷新父窗口
this.close();//关闭当前子窗口
而url传递的参数可以通过var str = window.location.href;获取的字符串进行解析获得