child.html必须是window.open()打开的才行

解决方案 »

  1.   

    <html>
    <head>
    <title>PARENT AND CHILD WINDOWS</title>
    <script language='JavaScript'>
    var newwin=new newwin();
    function newwin(alertmess){
        this.alertmess=alertmess;
    }
    function alertmess(){
        window.alert('success!');
    }
    </script></head>
    <body BGCOLOR="#c0c0c0">
    <a href="javascript:void(window.open('child.html'))">Create a  child window</a><br>
    <input type='submit' onclick=alertmess()>
    </body>
    </html>===============<html>
    <head>
    <script language='javascript'>
    function getParent(){
    window.opener.alertmess();
    }
    </script>
    <title>PARENT AND CHILD WINDOWS</title>
    </head>
    <body>
    <input type='submit' value='get parent message' onclick=getParent()>
    </body>
    </html>
      

  2.   

    也可以这样:
    <html>
    <head>
    <title>PARENT AND CHILD WINDOWS</title>
    <script language='JavaScript'>
    var newwin=new newwin();
    function newwin(){
        this.alertmess=alertmess;
    }
    function alertmess(){
        window.alert('success!');
    }</script></head>
    <body BGCOLOR="#c0c0c0">
    <a href="javascript:void(window.open('child.html'))">Create a  child window</a><br>
    <input type='submit' onclick=alertmess()>
    </body>
    </html>
    =======
    <html>
    <head>
    <script language='javascript'>
    function getParent(){
    window.opener.newwin.alertmess();
    }
    </script>
    <title>PARENT AND CHILD WINDOWS</title>
    </head>
    <body><input type='submit' value='get parent message' onclick=getParent()></body>
    </html>
      

  3.   

    还是不行啊!
    如果把子窗口里中window.opener.newwin.alertmess();里的newwin删掉就可以,
    window.opener.alertmess();
    这是为什么?
    我自己定义的对象中的方法定义有问题吗?
    麻烦给看看!
      

  4.   

    当前的源文件:
    parent.html
    ////////////
    <html>
    <head>
    <title>PARENT AND CHILD WINDOWS</title>
    <script language='JavaScript'>
    function alertmess(){
    window.alert('success!');
    }
    function newwin(){
    This.alertmess=alertmess();
    }newwin=new newwin();
    </script></head>
    <body BGCOLOR="#c0c0c0"><a href="javascript:void(window.open('child.html'))">Create a  child window</a><br>
    <input type='submit' onClick=alertmess()>
    </body>
    </html>child.html
    //////////////<html>
    <head>
    <script language='javascript'>function getParent(){
    if(window.opener.newwin==null){
    alert("newwin is null!");
    }
    window.opener.alertmess();
    }
    </script>
    <title>PARENT AND CHILD WINDOWS</title>
    </head>
    <body>
    <form name='newwindow'>
    <input type='submit' value='get parent message' onClick=getParent()>
    </form>
    </body>
    </html>
      

  5.   

    你是说我的parent.html里的自定义对象有问题?
    如果是应该怎么改啊?!
    我很着急!
      

  6.   

    function newwin(){
        this.alertmess=alertmess;
    }