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 14 of 14
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to self-close a Firefox window

    Been trying for three days to find a way to self close a FF window. The window is opened from a link on a board, and its only purpose is to run an onLoad script that launches a popup window, after which I need it to close itself. There are any number of ways to do this in IE, but nothing works in FF - the parent window remains open. Seems ridiculous that something so simple can't be done. Any help would be appreciated.

    Thx.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,211
    Thanks
    80
    Thanked 4,571 Times in 4,535 Posts
    ???? self.close() doesn't work???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Works in IE, not in FF.

    Here's the code -

    Code:
    <html>
    
    <head>
    <script language="javascript">
    
    function PopUp()
    {
    window.open('http://www.xxxxxxxxxxxx.com/network/testplayerpop.shtm','popup',
    'height=360,width=420,top=130,left=280,scrollbars=no');
    
    window.opener=top;
    window.self.close();
    }
    
    </script>
    </head>
    
    <body onLoad="PopUp()"></body>
    
    </html>
    Tried many variations on the last two lines of script - pretty much anything will close the window in IE, but nothing works in FF. Also tried a lot of hacks that may have worked in older versions, but don't work in 3.5.3. A common opinion is that the window must be opened by java to be closed by java, but can't do that from a url, and haven't come up with a workaround.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,211
    Thanks
    80
    Thanked 4,571 Times in 4,535 Posts
    ??? Just tried it myself, and it worked fine.

    BUT...

    But all 3 pages were of course in the local domain. I could see why it might be different when different domains are involved. If I get a chance, I'll try that. (I have a dozen domains I own & can play with.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by Krashsite View Post
    Works in IE, not in FF.

    Here's the code -

    Code:
    <html>
    
    <head>
    <script language="javascript">
    
    function PopUp()
    {
    window.open('http://www.xxxxxxxxxxxx.com/network/testplayerpop.shtm','popup',
    'height=360,width=420,top=130,left=280,scrollbars=no');
    
    window.opener=top;
    window.self.close();
    }
    
    </script>
    </head>
    
    <body onLoad="PopUp()"></body>
    
    </html>
    That window shouldn't even open since it gets blocked.
    I'm not sure of the effect of assigning to window.opener.
    To close a window that your script opened, you save the reference returned by the open function, then call its close method:

    Code:
    var wRef = window.open('http://www.xxxxxxxxxxxx.com/network/testplayerpop.shtm','popup',
    'height=360,width=420,top=130,left=280,scrollbars=no');
    
    ..........
    
    wRef.close();

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,211
    Thanks
    80
    Thanked 4,571 Times in 4,535 Posts
    Random: Read the first post.

    He clicks a link that opens a new window (I assume he means <a href="xxx" target="whatever">) and then that new window opens yet another window (the window.open he shows in his code) and then he wants the intermediate window (the one opened by the link) to be closed.

    So self.close() is the right operation, so far as I can see.

    I agree I see no reason for the window.opener statement. Possibly that is indeed the problem?

    EDIT: Added the window.opener to my test code; no difference. But again that's all happening in a single domain.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New Coder
    Join Date
    Jun 2010
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The first window can be opened from a link on any board, and everything else is in the same domain (one of mine). For example, i would post the link here in this post, to open a popup over this board (it contains a flash player).

    The popup doesn't get blocked because the board with the opening url opens it in a new window, just like any link - it sees it as another website. The landing page executes the onLoad, launches the popup, and closes, leaving the popup over the originating board. It's treated like a popup on any of my websites - the launching page and popup are in the same domain.

    My other option is to have the board link open a new window that's the same size as the popup. It looks a little different (can't get rid of the tool & address bars), but opens properly in IE and FF and works ok. Problem is there are links in the popup (homesite, support) and dropmenus that reload different players & playlists, and they work differently in IE and FF, causing all kinds of problems with window targeting and sizing.

    As I mentioned in my OP, the landing page that launches the popup is not opened with a script, but directly from a url, and that may prevent it from being closed by a script.

    The window.opener statement eliminates the warning popup in IE when the window self closes. I also tried onLoad="window.opener.close();" in the popup (to close parent from child). Works in IE, not in FF.
    Last edited by Krashsite; 06-17-2010 at 09:10 PM.

  • #8
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    This isn't tested but try opening the user-requested window like this:

    Code:
    <a href='default.url' onclick = "window.nw = window.open( 'popuURL', 'popupName' );return false">Open</a>
    Then in the popup:

    Code:
    <script language="javascript">
    
    function PopUp()
    {
    window.open('http://www.xxxxxxxxxxxx.com/network/testplayerpop.shtm','popup',
    'height=360,width=420,top=130,left=280,scrollbars=no');
    
     opener.nw.close();
    }
    </script>

  • #9
    New Coder
    Join Date
    Jun 2010
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    As far as I know, you cannot post any script in a link posted on a board in url tags. It has to be a direct http://xxxxxxx url.

  • #10
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by Krashsite View Post
    As far as I know, you cannot post any script in a link posted on a board in url tags. It has to be a direct http://xxxxxxx url.
    So you mean any third party site that opens all user-supplied links in a new window.
    As you have control over the player page which I understand to be on the same domain as its opener, then could the player page not execute something like:
    Code:
    try
    {
     if( self.opener )
      self.opener.close();
    }
    catch( e );
    ?

  • #11
    New Coder
    Join Date
    Jun 2010
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Just confirmed that FF will not allow javascript to close a window unless it was opened by javascript. I added another script file in front of the landing page, and the landing page opens the popup and closes itself, leaving the new page open behind it.

    Old: Board link -> Landing page -> Popup - Landing page won't close

    New: Board link -> Redirect page -> Landing page -> Popup - Landing page now closes because it was opened by script, but Redirect page won't close because it was opened by url.

    Trying to find a way around it, but looks like a dead end.

  • #12
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by Krashsite View Post
    Just confirmed that FF will not allow javascript to close a window unless it was opened by javascript.
    What is it that prevents the landing page containing the popup's content, without having to open a separate popup?

  • #13
    New Coder
    Join Date
    Jun 2010
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by randomuser773 View Post
    What is it that prevents the landing page containing the popup's content, without having to open a separate popup?
    IE and FF handle window targeting and resizing differently, and there appears to be a bug in IE6 that prevents resizing to a full window. There are 3 links and 2 dropmenus in the popup, and I can't get them to work the same in both browsers.

  • #14
    New Coder
    Join Date
    Jun 2010
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, I've managed to correct all the targeting & resizing problems I had in Firefox (what a horror show ), and I'm back to the original problem.

    How do I close a FF window that was not opened with a script?


  •  

    Posting Permissions

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