Return focus to same pop-up window repeatedly

R

Richard Shewmaker

I've only recently returned to (trying to) doing simple JS, so this is
probably a really lame question.

I have a Web page with a series of graphics in it (window A).

Clicking on a graphic in A opens a small pop-up window (window B) over A.

If the visitor clicks on B, it closes.

If the visitor clicks back on A -- the page or a new graphic -- A comes
to the forefront and hides B.

If B remains open (visitor does not click on it) and visitor clicks on
another graphic on A, the contents of B are replaced by whatever the new
link points to (or the same if the same graphic is clicked on).

I can make all the above happen. What I can't figure out is how to set
the focus back on B, so that it comes to the forefront, after clicking
on a graphic in A. I've messed around with focus() in all sorts of ways
but can't get B to come back to the foreground. My attempts include
adding a focus statement in the page loading (graphic.html in the
example below).

This is what works:

function secWin(url) {
window.open(url,"imagePopUp","width=270,height=225,left=50,top=50") ;
}

used as follows

<a href="javascript:secWin('graphic1.html');"> image </a>

I hope someone can straighten this out for me. Thanks.
 
R

Randy Webb

Richard Shewmaker said the following on 1/19/2006 12:52 AM:
I've only recently returned to (trying to) doing simple JS, so this is
probably a really lame question.

I have a Web page with a series of graphics in it (window A).

Clicking on a graphic in A opens a small pop-up window (window B) over A.

If the visitor clicks on B, it closes.

If the visitor clicks back on A -- the page or a new graphic -- A comes
to the forefront and hides B.

If B remains open (visitor does not click on it) and visitor clicks on
another graphic on A, the contents of B are replaced by whatever the new
link points to (or the same if the same graphic is clicked on).

I can make all the above happen. What I can't figure out is how to set
the focus back on B, so that it comes to the forefront, after clicking
on a graphic in A. I've messed around with focus() in all sorts of ways
but can't get B to come back to the foreground. My attempts include
adding a focus statement in the page loading (graphic.html in the
example below).

This is what works:

function secWin(url) {
window.open(url,"imagePopUp","width=270,height=225,left=50,top=50") ;

var myWindowReference = window.open(...);
myWindowReference.focus();
}

used as follows

<a href="javascript:secWin('graphic1.html');"> image </a>

http://jibbering.com/faq/#FAQ4_24




--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
 
R

Richard Shewmaker

Randy said:
Richard Shewmaker said the following on 1/19/2006 12:52 AM:

var myWindowReference = window.open(...);
myWindowReference.focus();


http://jibbering.com/faq/#FAQ4_24

Hi. Thank you. That was one of the attempts I made (so I don't feel
quite so stupid now). I figured since you were giving it to me here that
it must work ... so my first suspect was my browser. And guess what?
That's the problem.

It works just fine in IE6, Opera 8 on Win32, but it does not work in
Firefox 1.5! Time for me to add a note to that effect on Mozillazine.
 
G

Gérard Talbot

Randy Webb wrote :
Richard Shewmaker said the following on 1/19/2006 12:52 AM:

var myWindowReference = window.open(...);
myWindowReference.focus();

Randy, if the window is new, there is no need to focus() it. The focus
call should be done only if the url is different.

What the OP needed is an example like this one (3rd one, last one):

http://developer.mozilla.org/en/docs/DOM:window.open#Best_practices

Also, the user must check the checkbox "Allow scripts to:Raise or lower
windows to" in Mozilla or Firefox. Same thing with Opera 8+.

Gérard
 
G

Gérard Talbot

Richard Shewmaker wrote :
I've only recently returned to (trying to) doing simple JS, so this is
probably a really lame question.

I have a Web page with a series of graphics in it (window A).

Clicking on a graphic in A opens a small pop-up window (window B) over A.

If the visitor clicks on B, it closes.

If the visitor clicks back on A -- the page or a new graphic -- A comes
to the forefront and hides B.

If B remains open (visitor does not click on it) and visitor clicks on
another graphic on A, the contents of B are replaced by whatever the new
link points to (or the same if the same graphic is clicked on).

I can make all the above happen. What I can't figure out is how to set
the focus back on B, so that it comes to the forefront, after clicking
on a graphic in A. I've messed around with focus() in all sorts of ways
but can't get B to come back to the foreground. My attempts include
adding a focus statement in the page loading (graphic.html in the
example below).

This is what works:

function secWin(url) {
window.open(url,"imagePopUp","width=270,height=225,left=50,top=50") ;

If you do not set "resizable=yes" nor "scrollbars=yes" in the
windowFeatures string list, then the window will not be resizable and
will not render scrollbars if needed, if document box overflows
requested window dimensions.
}

used as follows

<a href="javascript:secWin('graphic1.html');"> image </a>

Do not use "javascript:" in links. "javascript:" starting an href value
is widely known as an error. "javascript:" in links reduces
accessibility, usability of links, user features, browser preferences in
all tested browsers.

http://jibbering.com/faq/#FAQ4_24

Also
http://developer.mozilla.org/en/docs/DOM:window.open#Usability_issues
I hope someone can straighten this out for me. Thanks.

Study the 3 examples, specially the 3rd example, at

Mozilla Developer Center on DOM:window.open
Best practices
http://developer.mozilla.org/en/docs/DOM:window.open#Best_practices

and you can have a look also at:

What does the "Raise or lower windows" setting do exactly?
http://www.gtalbot.org/Netscape7Section/Popup/PopupAndNetscape7.html#RaiseLowerSetting

Your browser+user/pref settings must allow scripts to raise or lower
windows. This can be the case in Mozilla 1.x, Firefox 1.x and Opera 8+.

Gérard
 
R

Randy Webb

Gérard Talbot said the following on 1/19/2006 3:33 AM:
Randy Webb wrote :


Randy, if the window is new, there is no need to focus() it. The focus
call should be done only if the url is different.

And that is it's purpose. To bring it back to the front when a second
page is attempted to be opened. If it is the first call, then the
focus() does no harm. But if it is the second call and the original
popup is behind the main window, it will bring it back to the front.
Unless the option is disallowed that you mention below.
What the OP needed is an example like this one (3rd one, last one):

http://developer.mozilla.org/en/docs/DOM:window.open#Best_practices
Also, the user must check the checkbox "Allow scripts to:Raise or lower
windows to" in Mozilla or Firefox. Same thing with Opera 8+.

That option I had forgotten about :)
 
L

leandro camargo

to make a window having focus repeatedly:

var wind1 = window.open('...','...','...');
var timer1 = setInterval( wind1.focus, 500 );

I think this solve the problem.
 
G

Gérard Talbot

Randy Webb wrote :
Gérard Talbot said the following on 1/19/2006 3:33 AM:

And that is it's purpose. To bring it back to the front when a second
page is attempted to be opened. If it is the first call, then the
focus() does no harm.

It does no harm but it won't be needed. That's why I prefer a code fork
(like in the 3rd example of the "Best Practices" section of the url below)
so that resorting to a focus() call is only done when needed.
But if it is the second call and the original
popup is behind the main window, it will bring it back to the front.
Unless the option is disallowed that you mention below.


That option I had forgotten about :)

Gérard
 
R

Richard Shewmaker

Thank you, Randy, Gérard, & Leandro --

I have a little more info which is helpful in a general way.

In Firefox 1.5 the JavaScript option for "raise or lower windows" is
turned off by default, and that's what caught me.

In my case the window was the same size each time because it was
bringing up an alternate image and all of them were the same size.

Without the focus(), the pop-up window does not come back to the
forefront (on top of the parent window), and I suspect that is because
the parent window is getting the focus as the result of a visitor
clicking a new link on it. It helps to know that the main window was
whatever size your browser had and the pop-up was much smaller, and
depending on where the main one was, it could disappear completely
behind the main one when that one had another link selected.

I'll definitely check out the Web sites indicated -- as I said, I've not
been using JS for a long time and am basically starting almost at
scratch again (sigh).

Many thanks.
 
T

Thomas 'PointedEars' Lahn

leandro said:
to make a window having focus repeatedly:

var wind1 = window.open('...','...','...');
var timer1 = setInterval( wind1.focus, 500 );

I think this solve the problem.

You have not tested this, have you? It introduces more problems than it
solves.


PointedEars
 
L

leandro camargo

If you talk about the line:
var wind1 = window.open('...','...','...');

I wrote it like that, but the user have to adapt to your own purpose.
If you talk about other problem post it here, I would like to know it.
 
T

Thomas 'PointedEars' Lahn

leandro said:
If you talk about the line:

Where?

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
var wind1 = window.open('...','...','...');

I was not talking about that but the above is of course part of the problem.
[...]
If you talk about other problem post it here, I would like to know it.

If you force a window to the foreground, you force all other windows to
the background. This may not include only browser windows, and it does
include _all other_ browser windows. What would you think of someone
who is crippling your desktop in such a way?


PointedEars
 
R

Randy Webb

Thomas 'PointedEars' Lahn said the following on 1/20/2006 1:12 PM:
leandro camargo wrote:
[...]
If you talk about other problem post it here, I would like to know it.

If you force a window to the foreground, you force all other windows to
the background. This may not include only browser windows, and it does
include _all other_ browser windows.

Only in the same family of browsers.
What would you think of someone who is crippling your desktop in such a way?

Better than someone who opens/re-navigates a window that I would have no
way of knowing it had been navigated if it were not in front of all
other windows.
 
P

Pierre Sudarovich

Richard Shewmaker a écrit :
I've only recently returned to (trying to) doing simple JS, so this is
probably a really lame question.

I have a Web page with a series of graphics in it (window A).

Clicking on a graphic in A opens a small pop-up window (window B) over A.

If the visitor clicks on B, it closes.

If the visitor clicks back on A -- the page or a new graphic -- A comes
to the forefront and hides B.

If B remains open (visitor does not click on it) and visitor clicks on
another graphic on A, the contents of B are replaced by whatever the new
link points to (or the same if the same graphic is clicked on).

I can make all the above happen. What I can't figure out is how to set
the focus back on B, so that it comes to the forefront, after clicking
on a graphic in A. I've messed around with focus() in all sorts of ways
but can't get B to come back to the foreground. My attempts include
adding a focus statement in the page loading (graphic.html in the
example below).

This is what works:

function secWin(url) {
window.open(url,"imagePopUp","width=270,height=225,left=50,top=50") ;
}

used as follows

<a href="javascript:secWin('graphic1.html');"> image </a>

I hope someone can straighten this out for me. Thanks.
Hi Richard,

<body onblur="focus();">

try this :)

amicably,

Pierre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top