Return focus to parent window w/ Javascript

Discussion of general topics about Mozilla Firefox
Locked
TruckStuff
Posts: 22
Joined: July 20th, 2004, 7:17 am

Return focus to parent window w/ Javascript

Post by TruckStuff »

I'm not sure which forum this belongs in, so I'll just put it in general.

I've created a popup window that has the following "close window" function:

Code: Select all

<script type="text/javascript">
<!--
function closeWin()
{
 window.opener.focus();
 self.close();
}
-->
</script>
This works fine in IE, but it dies in Firefox. The error is "window.opener.focus is not a function." Ehhh... ok, so how do I return the focus to the parent window with Firefox? Been googling for a while and haven't found anything. Also tried window.opener.document.focus(); and

Code: Select all

...
var parentWin = window.opener;
parentWin.focus();
...
Every variation returns the same error. Any help is appreciated.
Col_Boogie
Posts: 3
Joined: December 3rd, 2014, 3:04 pm

Re: Return focus to parent window w/ Javascript

Post by Col_Boogie »

In both parent and child window include the Javascript

Code: Select all

function here() {
var O = window.opener
    if (O) O.here()
    else    {
        alert('Welcome Back')
        window.focus()}
}
Some browsers are uneasy with that code (asks if user if sure they want to do that)
User avatar
malliz
Folder@Home
Posts: 43796
Joined: December 7th, 2002, 4:34 am
Location: Australia

Re: Return focus to parent window w/ Javascript

Post by malliz »

I doubt the OP has been waiting 15 years
What sort of man would put a known criminal in charge of a major branch of government? Apart from, say, the average voter.
"Terry Pratchett"
User avatar
James
Moderator
Posts: 28007
Joined: June 18th, 2003, 3:07 pm
Location: Made in Canada

Re: Return focus to parent window w/ Javascript

Post by James »

Holy Old Thread Batman!
Locked