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

Focus() window by Name NOT Reference

P: n/a
N/A
Hey all,

If I open a popup like this

window.open('http://www.google.com', 'popup', 'width = 618, height = 425,
directories = no, location = no, menubar = no, resizable = no, scrollbars =
yes, status = no, toolbar = no');

Then I know that there is a window object in the windows collection called
'popup'. So how can I make that window come to the front? Looking for
something like windows['popup'].focus()

I know you can set a variable to the window reference when you open the
popup ie( var x = window.open(); ) but this is not suitable in my
particular case. I need to be able to gain access to the window object
without having its direct reference...

Thanx
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DU
N/A wrote:
Hey all,

If I open a popup like this

window.open('http://www.google.com', 'popup', 'width = 618, height = 425,
directories = no, location = no, menubar = no, resizable = no, scrollbars =
yes, status = no, toolbar = no');

You need to remove all blank spaces in the 3rd parameter string list.

"windowFeatures is an optional string containing a comma-separated list
of options for the new window (do not include any spaces in this list)."
http://devedge.netscape.com/library/...w.html#1202731

Btw, why do you turn off the statusbar and remove the resizability of
the popup?
Then I know that there is a window object in the windows collection called
'popup'.
No. That's just a property of string type; it's not a window object
reference (pointer in memory).

So how can I make that window come to the front? Looking for something like windows['popup'].focus()

var WindowObjectReference ; // needs to be a global variable

function OpenRequestedPopup()
{
if(WindowObjectReference == null || WindowObjectReference.closed)
{
WindowObjectReference = window.open("http://www.google.com", "popup",
"width=618,height=425,resizable=yes,scrollbars=yes ,status=yes");
}
else if(!WindowObjectReference.closed)
{
WindowObjectReference.focus();
};

I know you can set a variable to the window reference when you open the
popup ie( var x = window.open(); ) but this is not suitable in my
particular case.
Why? Please elaborate.

Let me underline that the successful use of focus() implies that
javascript is enabled on the remote system. So trying to use the focus()
method on an opened secondary window by a target attribute with js
disabled cannot work.

I need to be able to gain access to the window object without having its direct reference...

Thanx


Then it's impossible. focus() is a method for a window object reference:
therefore you need a direct reference to it, a pointer in the memory heap.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #2

P: n/a
N/A
Thanks Laurent, perfect :)
"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> wrote in
message news:3F1247D2.2000805@bluewin_NO_SPAM.ch...
Hi,

N/A wrote:
Hey all,

If I open a popup like this

window.open('http://www.google.com', 'popup', 'width = 618, height = 425, directories = no, location = no, menubar = no, resizable = no, scrollbars = yes, status = no, toolbar = no');

Then I know that there is a window object in the windows collection called 'popup'. So how can I make that window come to the front? Looking for
something like windows['popup'].focus()

I know you can set a variable to the window reference when you open the
popup ie( var x = window.open(); ) but this is not suitable in my
particular case. I need to be able to gain access to the window object
without having its direct reference...

Thanx
You should always keep a reference (the 'x' in your example) to your
windows, but I can imagine cases where you really don't have access to
it. In these rare cases, you can gain a new reference to the opened
window with:

var newX = open( '', 'popup', '' );

After that, you can work with it like with a normal reference, for

example:
newX.focus();

Note however that this will open a new blank window if popup was
previously closed by the user. If you don't keep a reference on this
window somewhere (for example in a frameset), you have no way to know it
the window is still open or not.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.