在网上搜了好多,都没有很好的解决办法,说什么的都有,在这里想在弄懂这个方法的使用。
我在父页面中调用了子页面,用的是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是位于父页面的文本框,现在我要做的就是对子页面进行保存后,自动关闭子页面,并将其中子页面中的一个特定的文本框的值传入父页面中,可是这种方法不可行,在父页面中是得不到值的,请高手帮忙,是不是需要修改哪些地方,还是需要检查什么其他元素,非常感谢?

解决方案 »

  1.   

    opener.document.getElementById("index_0011").value = $('customname').value;这样 不加window;
      

  2.   

    LZ 的思路正确,这里有一简单的方法,合乎你的要求,有什么问题就提出
    父窗口. (名字随意)<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>
      

  3.   


    <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">
      

  4.   

    没有任何问题。
    把 $('customname').value; 改成字符串 常量 试试。
      

  5.   

    用法是没有任何问题的。父窗口得不到值应该是其他方面的原因。代码列举的不详细,不能判断具体原因。
    可先alert下$('customname').value的值,看看能否得到。
      

  6.   

    这个已经试过了,alert没有问题。
      

  7.   

    这里还有个问题要和大家详细说明一下,因为我这个用的是struts2,所以在父窗口打开子窗口是用的window.open方法。然后子窗口中有一个保存按钮,我点击保存按钮后,触发了一个方法,并进入了一个action中,那个action的result使用的是type="chain",然后又走了一次那个进入窗口的方法,也就是进入到了现在打开的这个页面。本人觉得好像和这个没有关系吧,因为我走完那个action后,window.close就把那个子页面关闭了啊
      

  8.   

    window.open方法必须放在事件之中打开,
    不然window.opener.document.getElementById打开对象为空

    <a href="#" onclick="window.open('test.html')">测试</a>正确
    <a href="javascript:window.open('test.html')" >测试</a>对象为空
    猜测,浏览器的消息机制有传递并刷新全局变量的功能