Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy closing a window from another page

    have a page where in this page I will pass a parameter to decide to close the window of the parent page or not, but it redirect me without closing the window..

    the code used in the child page:
    Code:
    var finish;
    parent.location="thegame.htm?finish="+1;
    the code in the parent page:

    Code:
    <script language="javaScript">
    
    finish=document.location.search;
    finish=finish.substring(finish.lastIndexOf("=")+1);
    
    
    function finishOrNot()
    {
      
      if (finish==1)
       {  
         document.window.close();
       }
    }
    </script>
    </head>
    <frameset  rows="330,*" frameborder="NO" border="0" style="margin: 0" onload="finishOrNot()"> 
      <frameset cols="*,198" frameborder="NO" >

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Why not directly close the parent from the child page instead of re-opening the page then eventually closing it?

    parent.close()
    or
    top.close()

    Take note that when closing parent windows (not spawned windows), a security prompt is displayed asking if the user wants to close the window or not. You cannot bypassed that prompt, you have to live with it. There is a bug on that, though, and there are exploits on it but the exploit is not recommended to be used since in the future, the bug may (will) be fixed.

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Hi glenngv ....
    I dont think that I have to live with that massege any more as this problem is solved by just two lins of code..

    parent.window.opener = self;
    parent.window.close();

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Which only does anything in iew. In other browsers (with the exception of Opera7, in whihc this is a known bug) the message will still appear. Note that that hack is one of those that might be fixed in the ie6.02 that comes with the new service pack for WinXP that is to be released this summer.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by romram
    Hi glenngv ....
    I dont think that I have to live with that massege any more as this problem is solved by just two lins of code..

    parent.window.opener = self;
    parent.window.close();
    That is exactly the exploit I was talking about.
    You can't rely on it as it will be fixed in future browser releases, just like liorean mentioned.

  • #6
    Regular Coder
    Join Date
    Sep 2002
    Location
    Nottingham, UK
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I am having a similar problem and not very good with javascript. I have the following pages:

    Category(A)
    Item 1(in category A)

    What I am trying to do is the following:

    When a user clicks on an item in the Category(A) page, a new window is opened and the Category(A) page is closed.

    I have seen the parent.close() but not sure how to use it or where to start....

    I tried putting it in the item1 page as <body onLoad=parent.close();> but this closes the item page and not the category(A) page.

    Any pointers would be greatly appreciated.

    Sarah
    You are not a human being having a spiritual experience, your a spiritual
    being having a human experience.


  •  

    Posting Permissions

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