Welcome to WebmasterWorld Guest from 54.234.8.146

Forum Moderators: open

Message Too Old, No Replies

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

     

physics

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



Seems that it might be intentional:
[bugzilla.mozilla.org...]

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

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month