Results 1 to 7 of 7

Thread: closing parent window when child opens

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Hi,
    I have been trying to close a parent window when it spawns a child using the opener.close method, but have had no success. When I try to run the javascript command in the child window it reports unterminated string or runtime error. Can anyone see the problem or provide source to do this?

    Source:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>

    <HEAD><TITLE>New Window Test</TITLE>
    <FORM>

    <BODY>
    <SCRIPT language=JavaScript>
    <!--
    function newWin()
    {


    pageContent = "<HTML><HEAD><TITLE>";
    pageContent += "Close Parent Test</TITLE>";

    pageContent += "</HEAD><FORM><BODY>";


    pageContent += "<script langauge='JavaScript'><!-- opener.close(); //--></script>";


    pageContent += "</BODY><FORM></HTML>";



    cardWindow = open("","cardWin","width=450,height=350,resizable=1");



    with (cardWindow.document)
    {
    open();
    write(pageContent);
    close();
    }

    }

    //-->
    </SCRIPT>

    <INPUT type=button value="New Window" onclick=newWin();>

    </BODY></FORM></HTML>

  2. #2
    Guest
    Try this code for closing your windows.


    Code:
    <script language="javascript">
    
    function closeWin()
    {
    window.close();
    };
    
    </script>
    
    <A HREF="javascript:closeWin();"
    onMouseOver="window.status='close the Window';return true";>close Window</A>

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Matthew will this not just close the current window. I want a parent to open a new window, and when the new window opens the parent closes.

    Thanks

    Lenin.

  4. #4
    Lively Member harsoni's Avatar
    Join Date
    Oct 2000
    Posts
    118

    Angry

    This is impossible i guess...

    sonia

  5. #5
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Originally posted by harsoni
    This is impossible i guess...

    sonia
    Don't guess!



    Code:
    Put the following in the child: 
    
    <script langauge="JavaScript"><!--
    opener.close();
    //--></script>
    
     
    
    Although you'll need to make sure that the opener has been defined for browsers that don't have it by default, by placing the following in the parent: 
    
    <script language="JavaScript"><!--
    msgWindow=open('',window,'resizable=no,width=200,height=200');
    msgWindow.location.href ='apage.html';
    if (msgWindow.opener == null) msgWindow.opener = self;
    //--></script>
    
     
    
    Note, that this will likely prompt the user for confirmation before closing the window.
    Mark
    -------------------

  6. #6
    Lively Member harsoni's Avatar
    Join Date
    Oct 2000
    Posts
    118
    Hey Mark,
    That is good you showed in fact we can close the parent window from the child window...but i have a problem how do u avoid the message box that pops up???


    Sonia

  7. #7
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I had a feeling that question would be next!

    this might help:
    http://developer.irt.org/script/366.htm

    I haven't tried it though



    (my last post came from www.irt.org as well)
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width