...

View Full Version : How to self-close a Firefox window



Krashsite
06-17-2010, 06:45 AM
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.

Old Pedant
06-17-2010, 07:03 AM
???? self.close() doesn't work???

Krashsite
06-17-2010, 06:54 PM
Works in IE, not in FF.

Here's the 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.

Old Pedant
06-17-2010, 08:27 PM
??? 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.)

randomuser773
06-17-2010, 08:37 PM
Works in IE, not in FF.

Here's the 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:


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

..........

wRef.close();

Old Pedant
06-17-2010, 08:42 PM
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.

Krashsite
06-17-2010, 09:00 PM
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. :confused:

randomuser773
06-18-2010, 01:16 AM
This isn't tested but try opening the user-requested window like this:


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

Then in the popup:


<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>

Krashsite
06-18-2010, 03:42 AM
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.

randomuser773
06-18-2010, 04:23 AM
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:


try
{
if( self.opener )
self.opener.close();
}
catch( e );
?

Krashsite
06-18-2010, 05:06 AM
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.

randomuser773
06-18-2010, 05:23 AM
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?

Krashsite
06-18-2010, 05:35 AM
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.

Krashsite
06-21-2010, 04:15 AM
Ok, I've managed to correct all the targeting & resizing problems I had in Firefox (what a horror show :eek:), and I'm back to the original problem.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum