参考这个:
javascript/Jscript实现父子窗体的互相引用问题近来有很多网友问关于如何利用javascipt实现弹出窗体与父窗体功能引用问题。
本人在以前的使用有一些这方面的体验,希望与大家分享一下。希望能对需要的网友有一些帮助。本文主要以例子为主,文后附有全部源代码。
实现父窗体,子窗体引用的关键在于下面几点:
(1)window.open.函数返回值是弹出子窗体的引用句柄。
(2)得到父窗体引用句柄。这是功能实现的关键,说起来也很简单。
self.opener返回窗体的父窗体。
(3)self,window,parent,top等实现的窗体引用是针对帧(frame/frameset)实现的,跟本文关系不大的。你如果利用parent得不到弹出窗体的父窗体的。本文只是针对窗体之间引用做简单的分析说明。源代码只是提供简单演示,很不完善,如果使用的话,请自己增加相应的出错检查等功能。〈HTML〉
〈HEAD〉
〈TITLE〉Welcome to ZosaTapo's WebSite:::::::::Powered By ZosaTapo〈/TITLE〉〈/TITLE〉
〈SCRIPT LANGUAGE="JavaScript"〉
〈!--
var child=null;
function testP(){
alert("Message in parent window!");
}function openwindow(){
if(child==null){
 child=window.open("child.htm");
}
}function callmethod(){
if(child!=null){
child.testC();
}
}function closewindow(){
if(child!=null){
child.close();
child=null;
}
}
//--〉
〈/SCRIPT〉
〈style type="text/css"〉
A:hover{color:#0000FF;text-decoration:underline}BODY{color:#FFFFFF;font-family:Courier New, Courier, mono}
〈/style〉
〈/HEAD〉〈BODY bgcolor="#000000"〉
〈!--Title content bengin--〉
〈p align=center 〉〈font size=6 color='#6699cc'〉〈b〉Welcome To ZosaTapo  Castle〈/b〉〈/font〉〈/p〉〈!--Body content bengin--〉
〈b〉Watch text Changing:〈/b〉〈br/〉
〈INPUT TYPE="text" id="author" value="changed by child"〉〈br/〉〈br/〉〈b〉Open  child Window:〈/b〉〈br/〉
〈input type="button" value="Open Child Window" onclick="openwindow();"〉〈br/〉〈br/〉〈b〉Call child  Method:〈/b〉〈br/〉
〈input type="button" value="Call Child Method" onclick="callmethod();"〉〈br/〉〈br/〉〈b〉Close child Window:〈/b〉〈br/〉
〈input type="button" value="Close Child Window" onclick="closewindow();"〉〈br/〉〈br/〉〈!--Footer content begin--〉
〈hr width=100%〉
〈p align=center 〉Powered By 〈a href="mailto:[email protected]"〉Zosatapo〈/a〉
〈/BODY〉
〈/HTML〉〈HTML〉
〈HEAD〉
〈TITLE〉Welcome to ZosaTapo's WebSite:::::::::Powered By ZosaTapo〈/TITLE〉〈/TITLE〉
〈SCRIPT LANGUAGE="JavaScript"〉
〈!--
var parwindow=null;
parwindow=self.opener;
function testC(){
alert("Message in child window!");
}function changetext(){
if(parwindow!=null){
 parwindow.document.all("author").value="zosatapo";
}
}function callmethod(){
if(parwindow!=null){
parwindow.testP();
}
}function closewindow(){
if(parwindow!=null){
parwindow.close();
parwindow=null;
}
}
//--〉
〈/SCRIPT〉
〈style type="text/css"〉
A:hover{color:#0000FF;text-decoration:underline}BODY{color:#FFFFFF;font-family:Courier New, Courier, mono}
〈/style〉
〈/HEAD〉〈BODY bgcolor="#000000"〉
〈!--Title content bengin--〉
〈p align=center 〉〈font size=6 color='#6699cc'〉〈b〉Welcome To ZosaTapo  Castle〈/b〉〈/font〉〈/p〉〈!--Body content bengin--〉
〈b〉Change parent Text:〈/b〉〈br/〉
〈input type="button" value="Change parent Text" onclick="changetext();"〉〈br/〉〈br/〉
〈b〉Call parent  Method:〈/b〉〈br/〉
〈input type="button" value="Call Parent Method" onclick="callmethod();"〉〈br/〉〈br/〉〈b〉Close parent Window:〈/b〉〈br/〉
〈input type="button" value="Close Parent Window" onclick="closewindow();"〉〈br/〉〈br/〉

解决方案 »

  1.   

    不明白你B页面的作用,既然是只有一个按钮,何不A直接弹出C?
    这样实现起来更方便------------  a.htm  --------------<input type="text" name="a" id="a"/>
    <input type="text" name="b"/>
    <input type="button" value="打开B" onclick="openWin('b.htm')"/>
    <script language="javascript">
    <!--
    function openWin( page ){
    feature = 'width=100,height=50,scrollbars=no,location=no,menubar=no';
    window.open(page,null,feature);
    }
    //-->
    </script>-------- b.htm ---------------<input type="button" value="打开C" onclick="openWin('c.htm')"/>
    <script language="javascript">
    <!--
    function openWin( page ){
    feature = 'width=240,height=100,scrollbars=no,location=no,menubar=no';
    win = window.open(page,'c',feature);
    win.opener = window.opener;
    window.close();
    }
    //-->
    </script>---------------- c.htm --------------<input type="text" name="c" id="c";/>
    <input type="button" value="传到A" onclick="passA()"/>
    <script language="javascript">
    <!--
    function passA(){
    try{
    v = document.getElementById("c").value;
    opener.document.getElementById("a").value=v;
    window.close();
    }catch(e){
    alert(e.message);
    }
    }
    //-->
    </script>
      

  2.   

    A页面是Seller周报信息, 上面显示的是Seller本周实现的一些基本信息(WeeklyReport表) + 拜访的客户信息(列表  WeeklyReportCustomer表).
    页面上有个AddButton, 每按一下添加一个空客户.  客户是在已有公司中选择而不是手工填写. 按下联系人栏Button, 弹出该销售所有的客户(Customer表)B页面.
    在B页面上选择一个客户, 弹出C页面, 读取Customer表中信息显示出来, 填写新信息 拜访纪要后 回传给A页面. 返回C页面所有的信息, 客户姓名在A页面上显示出来.
    A页面始终没刷新, 脚本实现所有功能.
    我现在根本没能力做.
    A向后带的是 以后要返回显示的控件名, 这怎么带
    C页面返回的是一个对象, 怎么带?