homepage Welcome to WebmasterWorld Guest from 54.227.89.236
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Open a new window and then re-focus back on main window
physics




msg:3234262
 8:30 pm on Jan 27, 2007 (gmt 0)

I want to open a new window and then re-focus back on the main window. Window 2 is technically a popup I guess but in this case both windows will be visible at the same time (resize and move to make this work). I've tried to do this simply by
- Opening a second window and assigning it to the window2 var name.
- Using:
if(window2.focus()){
window.focus();
}

Also, I even tried putting the above code in a timer that runs in the first window but it doesn't seem to work.

What I really want to do is make the browser put focus on a text box in the first window every few seconds even after the user does something in the second window. I tried using document.getElementById('text-box-id').focus() but that doesn't seem to work either.

Any help?

(And yes, I know popups are dumb but I still need to do this ;) )

 

rocknbil




msg:3234273
 8:49 pm on Jan 27, 2007 (gmt 0)

Did you try window.opener.focus();?

Or window.opener.document.focus()

To re-focus on objects in the window opener,

window.opener.document.getElementById('field_id');

physics




msg:3236156
 6:16 pm on Jan 29, 2007 (gmt 0)

Thanks rocknbill. I was hoping to do all of the control from within the first window so I'm not sure opener is the way to go though.

physics




msg:3248098
 11:30 pm on Feb 9, 2007 (gmt 0)

My original code, i.e. just the simple code to focus back on a window once a second window opens, works on IE and Opera. Firefox seems to have an issue (maybe intentional) that if I open a second window then I cannot take the focus back from it. This may be a security measure of some kind but I'd like a way around it. Anyone have ideas?

physics




msg:3248152
 1:14 am on Feb 10, 2007 (gmt 0)

rocknbil, it turns out I could use your method, at least at one point in my code. However, even this didn't work on Firefox...

physics




msg:3248736
 7:21 pm on Feb 10, 2007 (gmt 0)

Seems that it might be intentional:
https://bugzilla.mozilla.org/show_bug.cgi?id=310825

Also in Firefox preferences in JavaScript -> Advanced the default is for raise or lower windows to be disabled.

I can see why they'd want to not allow a window to keep grabbing focus back but I'd think a window would be allowed to give focus away to it's parent if it wants to.

rocknbil




msg:3250026
 1:13 pm on Feb 12, 2007 (gmt 0)

Well there may be something else wrong. I know this because I have an application that takes the data out of a text box in the main window, opens it in a full screen new window for editing, then when you're done editing puts it back in the original box and closes the new window. Although you can't close or alter the opener itself, you should be able to work with items in the opener document.

Let's see some code, Fotiman will set you up. :-)

physics




msg:3250367
 7:01 pm on Feb 12, 2007 (gmt 0)

I found a workaround which was to not totally hide the bottom (opener) window so the user could still see the important part. That way the user gives focus back to it.
rocknbill, thanks for the help but I think this really is a restriction put in place by the Firefox folks specific to focus to avoid popunder windows. Makes sense if you don't have a popup blocker I guess but if you do and someone allows popups for a specific site then those popups should be allowed to manage focus I think... By breaking the focus functionality you're just restricting what web-based apps are allowed to do.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved