在网上搜了好多,都没有很好的解决办法,说什么的都有,在这里想在弄懂这个方法的使用。
我在父页面中调用了子页面,用的是window.open方式,
具体代码如下: function emuladd(){
newopen = window.open("","test","status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top=200,left=100,width=850,height=450");
document.forms[0].action="testAddLowCusAllInfo.html?selectButtonMenu=5&flag="+'booking';
document.forms[0].target="test";
document.forms[0].submit();
intervalFunc = setInterval('reloadPage()',10); }
function reloadPage(){
if(newopen.closed){
window.clearInterval(intervalFunc);
window.location.href = "bizBookingProStartOpen.html?projectkind="+$('projectkind').value;
}
}
然后在进入的子页面中加入了以下代码: alert("保存成功");
window.opener.document.getElementById("index_0011").value = $('customname').value;
window.close();
以上的customname是我在子窗口中得到的值,index_0011是位于父页面的文本框,现在我要做的就是对子页面进行保存后,自动关闭子页面,并将其中子页面中的一个特定的文本框的值传入父页面中,可是这种方法不可行,在父页面中是得不到值的,请高手帮忙,是不是需要修改哪些地方,还是需要检查什么其他元素,非常感谢?
我在父页面中调用了子页面,用的是window.open方式,
具体代码如下: function emuladd(){
newopen = window.open("","test","status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top=200,left=100,width=850,height=450");
document.forms[0].action="testAddLowCusAllInfo.html?selectButtonMenu=5&flag="+'booking';
document.forms[0].target="test";
document.forms[0].submit();
intervalFunc = setInterval('reloadPage()',10); }
function reloadPage(){
if(newopen.closed){
window.clearInterval(intervalFunc);
window.location.href = "bizBookingProStartOpen.html?projectkind="+$('projectkind').value;
}
}
然后在进入的子页面中加入了以下代码: alert("保存成功");
window.opener.document.getElementById("index_0011").value = $('customname').value;
window.close();
以上的customname是我在子窗口中得到的值,index_0011是位于父页面的文本框,现在我要做的就是对子页面进行保存后,自动关闭子页面,并将其中子页面中的一个特定的文本框的值传入父页面中,可是这种方法不可行,在父页面中是得不到值的,请高手帮忙,是不是需要修改哪些地方,还是需要检查什么其他元素,非常感谢?
父窗口. (名字随意)<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script language="javascript">
function openwin()
{
var url="2.html";
var mydata=showModalDialog(url,null,"dialogWidth:300px;dialogHeight:120px;center:yes;help:No;status:no;resizable:Yes;edge:sunken");//得到子窗口返回值
if(mydata)
alert("您从子窗口输入的值为:" +mydata.value);
}
</script>
</head>
<body>
<input id="Button1" type="button" value="打开窗口" onclick="openwin()" />
</body>
</html>
子窗口(名字是:2.html)<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
<script language=javascript>
function ReturnWin()
{
var returnData=new Object(); //创建变量
returnData.value=document.getElementById("Text1").value; //设置变量的值
window.returnValue=returnData; //窗体返回数据
window.close(); //关闭窗口
}
</script>
</head>
<body>
<input id="Text1" type="text" /><input id="Button1" type="button" value="保存" onclick="ReturnWin()" />
</body>
</html>
<script>
function $(s){
return document.getElementById(s);
}
function emuladd(){
newopen = window.open("","test","status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top=200,left=100,width=850,height=450");
document.forms[0].action="testAddLowCusAllInfo.html?selectButtonMenu=5&flag="+'booking';
document.forms[0].target="test";
document.forms[0].submit();
intervalFunc = setInterval('reloadPage()',10); }
function reloadPage(){
if(newopen.closed){
window.clearInterval(intervalFunc);
window.location.href = "bizBookingProStartOpen.html?projectkind="+$('projectkind').value;
}
}
</script>
<form>
<input type="text" id="index_0011">
<input type="text" id="projectkind" value="xxx">
<input type="button" onclick="emuladd()">
</form>
testAddLowCusAllInfo.html<script>
function $(s){
return document.getElementById(s);
}
window.onload=function(){
alert("保存成功");
window.opener.document.getElementById("index_0011").value = $('customname').value;
window.close();
}
</script>
<input type="text" id="customname" value="xxxxxxxx">
把 $('customname').value; 改成字符串 常量 试试。
可先alert下$('customname').value的值,看看能否得到。
不然window.opener.document.getElementById打开对象为空
如
<a href="#" onclick="window.open('test.html')">测试</a>正确
<a href="javascript:window.open('test.html')" >测试</a>对象为空
猜测,浏览器的消息机制有传递并刷新全局变量的功能