这个问题困扰了好久了,论坛上一直没有找到。
有三个页面,1.html中嵌入了iframe 2.html,在2.html中使用了一个showModalDialog的弹出窗口,我想实现把2.html弹出窗口的值传回到1.html的文本框中
1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head> <body> <input type="text" id="txtfile">
  <iframe src="2.html" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" width="700" height="460"></iframe>
 </body>
</html>2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head> <body>
 <script>
function winopen()
{
window.showModalDialog("3.html", window, "dialogWidth: 400px; dialogHeight: 200px; help: no; scroll: no; status: no");
}
 </script>
  <input type="button" value="弹出窗口" onclick="winopen();">
 </body>
</html>3.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head> <body>
 <script>
 function test()
 {
parent.document.getElementById("txtfile").value = "ok";
 }
 </script>
 <input type="button" value="测试" onclick="test();">
 </body>
</html>

解决方案 »

  1.   

    在2.html的JS里,获得showModalDialog的值肯定没问题吧,都在一个window域里.
    要传回到1.html的文本框中,只需要在2.html中用 window.parent.document.getElementById('txtfile').value=你那个值; 这样就行了.
      

  2.   


    function test()
     {
    parent.document.getElementById("txtfile").value = "ok";
     }我就是这样写的,不行,提示找不到txtfile
      

  3.   

    在3.html中 用 parent.document.getElementById("txtfile").value = "ok"; parent是2.html
    不能找到1.html的txtfile,试试window.parent.parent.document.getElementById("txtfile").value ="ok"
      

  4.   

    2.html
    function callback(a){
    parent.document.getElementById("txtfile").value =a;
    }
    function winopen()
    {
    window.showModalDialog("3.html", callback, "dialogWidth: 400px; dialogHeight: 200px; help: no; scroll: no; status: no");
    }3.html的
    function test(){
    var myObj = window.dialogArguments;
    var a='';//你需要传的值
    myObj(a);
    }
      

  5.   

    我没往下看代码,没看到下面是怎么样子.假设了你接收showModalDialog是没问题的.
    现在一看,是你对showModalDialog的使用有问题.有两种修改方法:
    第 1种,最接近你原来的方式,但不一定行:2.html里
    window.showModalDialog("3.htm",window,"dialogWidth: 400px; dialogHeight: 200px; help: no; scroll: no; status: no");3.html里
     function test()
     {
    window.dialogArguments.parent.document.getElementById("txtfile").value = "ok";
     }
    第 2种:2.html里
    var 在2里接收到的返回值=window.showModalDialog("3.htm",, "dialogWidth: 400px; dialogHeight: 200px; help: no; scroll: no; status: no");
    window.parent.document.getElementById('txtfile').value=在2里接收到的返回值;3.html里
    在返回之前,用 window.returnValue="ok";
      

  6.   

    theforever  用第一种方法解决了,还是showModalDialog没有仔细研究,非常感谢。