Click to See Complete Forum and Search --> : Popup Windows and Focus Help


DanTheMan
01-15-2003, 04:35 PM
I am building a site that uses a button to call up a javascript function for a new window for a "press section". Here is the function I am using:

function newWindow() {

window.open ('press_facts.html','presswindow','width=595,height=400,toolbar=yes,scrollbars=yes,resizable=yes');
}

Then, attached to the "press Section" button I have this call for the function:

onClick="newWindow()"

My problem is this: Is there a way to bring the press section window into focus (front layer) everytime it is clicked. Even if the user has unknowingly sent it to the back and it is still open when the button on the main page is clicked. Is there some simple thing I am missing or will I need to program this differently. Thank you in advance.

Dan

AdamBrill
01-15-2003, 05:01 PM
hmm... there isn't anything that does exactly that. You could try something like this:

function newWindow() {

win = window.open ('press_facts. html','presswindow','width=595,height=400,toolbar=
yes,scrollbars=yes,resizable=yes');
win.focus();
}

That makes it blink on the start bar if it isn't the top window. Otherwise, you could try this:

win=null;
function newWindow()
{
if(win) win.close();
win = window.open ('','presswindow','width=595,height=400,toolbar=yes,scrollbars=yes,resizable=yes');
}

that will make it close the window if it is open, then reopen it. I hope that helped!

DanTheMan
01-15-2003, 06:54 PM
The code that closes the window then reopens it seemed to work. However, Netscape 4.79 didn't like it very much. The button would just stop working. In MSIE it acted strange too. It would work for a while and then seem to get mixed up...it would open the window and then close it...backwards. Any other ideas? Thanks.

dan

AdamBrill
01-16-2003, 08:05 AM
Well, that's the only way that I know of doing it. Did you try the win.focus() method? That might be better if my other code doesn't work in netscape 4. The code works fine for me in IE, though, so I don't know what it is doing for you...

Webskater
01-16-2003, 09:19 AM
If what you want to do is make sure that, if the press window is open it always has the focus, then (and I presume here that when it first opens it is always at the front - I have never come across a window that opens behind other windows) in the body tag write:
onblur=window.focus()
If anyone clicks on windows behind the focus jumps straight back to the original window. (note: this is not foolproof and someone quick on the mouse can trigger an event on the pages behind.)

DanTheMan
01-16-2003, 02:43 PM
Thank you to all that helped out. I went ahead and used the last suggestion of adding the onblur command to the body tag. Thank you for your help adam, I am sure that something in my coding was screwing up your suggestion.

Dan