父窗口:
url = url + '?winFlg=aaa&winPig=bbb';
window.open(url, '', '');
子窗口:
var URLParams = new Object();
var aParams = document.location.search.substr(1).split('&');
for (var i=0; i < aParams.length; i++) {
var aParam = aParams[i].split('=');
URLParams[aParam[0]] = aParam[1];
}
alert(URLParams["winFlg"]);
alert(URLParams["winPig"]);
==================================================================================
打开一个新窗口,该子窗口调用父对象的方法或变量,这个问题一直没有搞清楚。网上找了些资料,总结一下:
打开新窗口一般有几种方法,window.open(...),window.showModalDialog(...),以及iframe中嵌套页面这里也一起研究吧,另外还有window.navigate(...)、window.location.href="..."、window.history.back(-1);都是实现同意页面内容跳转的,这里不讨论。
1、open子窗口:用window.opener代表父窗口的window对象
2、模态子窗口:间接通过传window对象到子窗口,然后子窗口可获得父窗口的window对象
3、iframe中子页面:用window.parent代表父窗口的window对象
父页面:1.htm 代码:
<html>
<head>
<title>打开父子窗口传值研究-父窗口</title>
<script >
var parValue="现在显示了父窗口中的变量值";
function test(){
alert("现在显示了父窗口中的方法正常执行");
}
</script>
</head>
<body >
<input type="button" id="mybutton1" value="打开open新窗口" onclick="window.open('2.htm');">
<input type="button" id="mybutton2" value="打开modal窗口" onclick="window.showModalDialog('3.htm',window);" >
<br>
<iframe id="subiframe" name="subiframe" src="4.htm" scrolling="auto" frameborder="1" ></iframe>
</body>
</html>
2.htm 代码:
<html>
<head>
<title>打开父子窗口传值研究-open打开子窗口</title>
<script>
var buttonValue=window.opener.document.getElementById("mybutton2").value //获取父窗口中的对象
var parentValue=window.opener.parValue; //获取父窗口中的变量
function doParTest(){
window.opener.test(); //调用父窗口中的方法
}
</script>
</head>
<body>
<input type="button" value="open打开子窗口按钮" onclick="alert('buttonValue:'+buttonValue);alert('parentValue:'+parentValue);doParTest()">
</body>
</html>
3.htm 代码:
<html>
<head>
<title>打开父子窗口传值研究-打开modal子窗口</title>
<script>
var parentWin=window.dialogArguments;
var buttonValue=parentWin.document.getElementById("mybutton2").value //获取父窗口中的对象
var parentValue=parentWin.parValue; //获取父窗口中的变量
function doParTest(){
parentWin.test(); //调用父窗口中的方法
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<input type="button" value="modal子窗口按钮" onclick="alert('buttonValue:'+buttonValue);alert
('parentValue:'+parentValue);parentWin.test();">
</body>
</html>
4.htm 代码:
<html>
<head>
<title>打开父子窗口传值研究-iframe中子窗口</title>
<script>
var buttonValue=window.parent.document.getElementById("mybutton2").value //获取父窗口中的对象
var parentValue=window.parent.parValue; //获取父窗口中的变量
function doParTest(){
window.parent.test(); //调用父窗口中的方法
}
</script>
</head>
<body>
<input type="button" value="iframe中子窗口按钮" onclick="alert('buttonValue:'+buttonValue);alert('parentValue:'+parentValue);doParTest()">
</body>
</html>
下面是自己写了一个测试例子:
test1:
<input type="text" id="txt">
<div style="float:left;" id="div" ></div>
<input type="button" value="open" onClick="openWindow()">
<script>
function openWindow(){
var result=window.showModalDialog("test2.html",window);
alert(result);
var arr = result.split('_');
var arrCodes = arr[0].split(',');
var arrNames = arr[1].split(',');
document.getElementById('txt').value=arr[1];
var innerH = '';
for(var i=0;i<arrCodes.length-1;i++){
innerH+='<input type=\"text\" name=\"old\" value=\"'+arrCodes[i]+'\" />'
}
document.getElementById('div').innerHTML=innerH;
}
</script>
test2:
<html>
<head>
<script>
function onload(){
var parentWin = window.dialogArguments;
var obj = parentWin.document.getElementsByName('old');
var oldValues = new Array();
for(var i=0;i<obj.length;i++){
oldValues[i]=obj[i].value;
}
var obj = document.getElementsByName('selectValues');
for(var i = 0;i<obj.length;i++){
for(var j=0;j<oldValues.length;j++){
if(obj[i].value == oldValues[j])
{ obj[i].checked='checked';}
}
}
}
function ok(){
var industryCodes = new Array();
var industryNames = new Array();
var tmpCodes = '';
var tmpNames = '';
var codes = document.getElementsByName("selectValues");
var names = document.getElementsByName("selectNames");
for(var i =0 ,j=0 ; i <codes.length;i++){
if(codes[i].checked){
tmpCodes += codes[i].value+',';
tmpNames += names[i].value+',';
j++;
}
}
var tmpValue =tmpCodes+'_'+tmpNames;
window.returnValue = tmpValue;
window.close();
}
</script>
</head>
<body onload="onload()">
<input type="text" id="test1" value="" />
<input type="checkbox" name="selectValues" value="1" />文本1<input type="hidden" name="selectNames" value="文本1" />
<br>
<input type="checkbox" name="selectValues" value="2" />文本2<input type="hidden" name="selectNames" value="文本2" />
<br>
<input type="checkbox" name="selectValues" value="3" />文本3<input type="hidden" name="selectNames" value="文本3" />
<br>
<input type="button" onclick="ok()" />
</body>
</html>
模态弹出窗口
returnValue除了可以是布尔值,整型值等以外还可以是个js数组,用来传递大量数据。
showModalDialog,是模态窗口,始终获得焦点,但弹出的窗体不能刷新,此弹出的窗口 里操作button,要想不弹出新窗口,需在
弹出的窗口中在<head>和</head>之间加<base target="_self">。
分享到:
相关推荐
1、CListCtrl控件:设置CListCtrl网格,内容项隔行变色,插入一行数据,删除数据,选中整行,双缓冲技术解决闪烁问题等。。 2、模态对话框及非模态对话框的使用 3、父子窗口间传值
pyqt父子窗口相互传值,网上都是简单的介绍,同类的demo基本没有找到。 希望该demo能帮到需要的朋友。
Qt主窗口与子窗口之间相互传值,对新手有帮助。
Web开发中的window.open父子窗口传值问题 部署在tomcat中进行
具体实现动态增删table以及后台传值; 与弹出窗口父子窗口传值
主要介绍了js操作模态窗口及父子窗口间相互传值,需要的朋友可以参考下
两个窗口传值,关于进程等问题,两个窗口传值,关于进程等问题
通过window.showModalDialog实现模态窗体,并将返回值回写父窗体
NULL 博文链接:https://phpxiaoxin.iteye.com/blog/423340
asp.net父子页面传值,资源共享是为了共同进步, 希望帮助需要的兄弟。
本文实例讲述了JS简单实现父子窗口传值功能。分享给大家供大家参考,具体如下: 父窗口页面father.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE&...
javascript showModalDialog传值与FireFox的window.open 父子窗口传值示例代码。
[C# 窗体间传值_共6种方法_低中高级实现方法_SongQz编著,窗体间传值是必然遇到的问题,希望我总结的这6种方法,能帮助到大家,代码100%保证完美实现; 代码最低用VS2010版打开。
window.showModalDialog以及window.open用法简介
使用VS2015写的MFC子窗口与父窗口之间消息的传递,可以直接执行
用途:把父页面的数据表格中的指定行数据传递到子页面,在子页面中把数据传递到父页面。内有项目一个,说明文本一个。
WPF父子窗体传输示例,父窗体向子窗体传参。子窗体回传参数到父窗体。 WPF showdialog模式。