Assistance with JavaScript
July 10, 2006 10:46 PM   RSS feed for this thread Subscribe

Javascript: How to focus on the original window after opening additional windows?

Hi,

I have a Javascript function that does the following:

window.open('http://jobsearchlog.com','jsl');
document.myform.submit();
opener.focus();

The window gets created and populated correctly.
The form submits and the original window displays a job ad.
I want the Originating window to get the focus at that point.
I have tried the following -
opener.focus();
window.focus();
document.window.focus();

I need to try to get a little sleep but would appreciate any assistance that you could provide.

Michael
posted by mickbw to computers & internet (5 comments total)
This is a pretty decent experts-exchange answer on focusing on a parent window when interfacing with a child popup. Hopefully it answers your question.
posted by purephase at 10:57 PM on July 10, 2006


Try this?
self.opener.window.document.focus()

posted by evariste at 11:42 PM on July 10, 2006


Your function is all in the opening window?

Surely you need to have a function in the popup which sends focus back to the opener?
posted by AmbroseChapel at 11:56 PM on July 10, 2006


First some analysis:


1. window.open('http://jobsearchlog.com','jsl'); //you've got a popup
2. document.myform.submit(); //the window that created the popup
3. opener.focus(); //a parent to line 2?!!


Three levels of windows? Ewww!

Now, assuming this all on the same page, then ask yourself what is the target of your form...if you don't have a target in your form (which I assume you don't but ya never know) then line 3 will never be executed because the page will be submitted to your form action in line 2, end of story. That's why you're never getting focus. The correct syntax is window.focus(), the self. is redundant. Although you're setup sounds like a dog's breakfast, the easiest solution would be to put a window.focus() in the onload of the the page your form submits to.

I also don't know if you know that opener is used by a popup to refer to the window that opened it. So like AmbroseChapel hinted, you could use opener.focus() from the onload of the popup too, but that's dicey since there's no guarantee the form will be submitted by then.
posted by furtive at 2:26 AM on July 11, 2006 [1 favorite]


I can clarify a little better now that I'm a little more awake and can see what I need to do.

I was creating an instance of my page, then submitting the form on the original page but couldn't change the focus back to the original page then.

What I need to do is just use the form values I am receiving on this page to insert a record into the database, do a window.open to the page I want to receive focus, and then hopefully refresh the parent window to reflect the preferences that were created in the

That will give me the page I want to open and my page with updated values available for their use.

Thanks for helping me clear the fog from a late night coding session and trying to remember what I did early in the morning.
posted by mickbw at 5:29 AM on July 11, 2006


« Older Do any strategy / pseudo-strat...   |   How do I process user ratings ... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Where does the DTD go? February 22, 2008
Hekp me move a div! February 24, 2007
alternative to XMLHttpRequest March 12, 2006
Help me read this Javascript and pass the right... February 20, 2006
Is there such thing as Javascript Tidy? November 12, 2005