Click to See Complete Forum and Search --> : Bringing a window to front


Helix
09-16-2003, 05:44 AM
I want to bring a window to front (activate it), having the corresponding window object, of course.

Shoudn't "window.focus" work? It doesn't work for me.

And another thing: is it possible to keep track of other instances of IE? For example, somebody may want to iterate through the windows opened with "window.open" (how to get their "window" object)

Thanks in advance.

Webskater
09-16-2003, 06:57 AM
I'm not entirely sure what you are trying to do but it sounds like you might be trying to prevent people from opening multiple windows.
If this is so you can do this by:
using window.open to open new windows and naming the window object
checking before using window.open whether the window object you are about to open exists
If it does use location.replace to put your new page in the existing window
If it does not exist use window.open to open a new window
In this way you can make sure that only one instance of a pop-up window is open at any time.
Sorry, if I have missed the point.

Helix
09-23-2003, 06:50 AM
You didn't miss the whole point. Let me explain myself.

On a page I have many thumbnails of some items. When the user clicks a thumbnail I'm displaying a window with a description of that item. Multiple popup windows may coexist because I'm assigning unique names to the windows (in the window.open call). That's not the problem.

The problem is when the user clicks on a thumb, doesn't close the popup and clicks again on the same thumb. Nothing is happening (actually, the document is re-written but I can't see that because the popup doesn't receive focus).

Ideally, this is what I should do:
---Check if the popup already exists;
---If it doesn't, create it;
---If it does, just bring it to front so the user can see it;



Unfortunately, I don't know how to check if a window with a given name exists and I also didn't succeed in bringing it to front. Can you help me?

Charles
09-23-2003, 07:01 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<ul>
<li><a href="http://www.bettiepage.com/images/photos/bikini/bikini1.jpg" onclick="win = window.open(this.href, 'child', 'height=400,width=300'); win.focus(); return false">Bettie 1</a></li>
<li><a href="http://www.bettiepage.com/images/photos/bikini/bikini2.jpg" onclick="win = window.open(this.href, 'child', 'height=400,width=300'); win.focus(); return false">Bettie 2</a></li>
<li><a href="http://www.bettiepage.com/images/photos/bikini/bikini3.jpg" onclick="win = window.open(this.href, 'child', 'height=400,width=300'); win.focus(); return false">Bettie 3</a></li>
<li><a href="http://www.bettiepage.com/images/photos/bikini/bikini4.jpg" onclick="win = window.open(this.href, 'child', 'height=400,width=300'); win.focus(); return false">Bettie 4</a></li>
</ul>

Helix
09-23-2003, 03:52 PM
Thanks. It works. I don't know what went wrong then.