By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,214 Members | 2,099 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,214 IT Pros & Developers. It's quick & easy.

Return focus to same pop-up window repeatedly

P: n/a
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.
Jan 19 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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.

Jan 19 '06 #2

P: n/a
Randy Webb wrote:
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


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.
Jan 19 '06 #3

P: n/a
Randy Webb wrote :
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();


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...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
--
remove blah to email me
Jan 19 '06 #4

P: n/a
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...ability_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...Best_practices

and you can have a look also at:

What does the "Raise or lower windows" setting do exactly?
http://www.gtalbot.org/Netscape7Sect...seLowerSetting

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
--
remove blah to email me
Jan 19 '06 #5

P: n/a
Gérard Talbot said the following on 1/19/2006 3:33 AM:
Randy Webb wrote :
Richard Shewmaker said the following on 1/19/2006 12:52 AM:
<snip>

function secWin(url) {
window.open(url,"imagePopUp","width=270,height=225 ,left=50,top=50") ;
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.


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...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 :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 19 '06 #6

P: n/a
to make a window having focus repeatedly:

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

I think this solve the problem.

Jan 19 '06 #7

P: n/a
Randy Webb wrote :
Gérard Talbot said the following on 1/19/2006 3:33 AM:
Randy Webb wrote :
Richard Shewmaker said the following on 1/19/2006 12:52 AM:
<snip>

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

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.


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.
What the OP needed is an example like this one (3rd one, last one):

http://developer.mozilla.org/en/docs...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 :)


Gérard
--
remove blah to email me
Jan 19 '06 #8

P: n/a
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.
Jan 19 '06 #9

P: n/a
leandro camargo wrote:
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
Jan 20 '06 #10

P: n/a
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.

Jan 20 '06 #11

P: n/a
leandro camargo wrote:
If you talk about the line:
Where?

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
<URL:http://www.safalra.com/special/googlegroupsreply/>
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
Jan 20 '06 #12

P: n/a
Thomas 'PointedEars' Lahn said the following on 1/20/2006 1:12 PM:
leandro camargo wrote:
<snip>
[...]
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 20 '06 #13

P: n/a
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
Mar 3 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.