this.window.focus() vs. window.focus() vs. this.focus()

R

Roger

Hi,

I am confused about the differences between this.window.focus(),
window.focus(), and this.focus().

I want to use the calls in a <body onload="..."> tag. What are the
differences between these forms that may make one succeed and another
fail? In particular, this.window.focus() fails in Opera 9.10 with an
"object not found", and windows.focus() succeeds in Opera 9.10, Firefox
2.02, and IE 7.

Roger
 
R

RobG

Hi,

I am confused about the differences between this.window.focus(),
window.focus(), and this.focus().

I want to use the calls in a <body onload="..."> tag. What are the
differences between these forms that may make one succeed and another
fail?

this.window.focus()
When used in-line in the body tag, 'this' refers to the body element.
In a standard DOM, the body element doesn't have a window property;
trying to call a method of a non-existent property will result in a
script error.

window.focus()
This calls the focus method of the window object, which should work in
standards-compliant browsers though it may not have any effect. Some
browsers provide user configurable settings so that users can prevent
script from raising or lowering windows.

this.focus()
This will attempt to call the focus method of the body element. The
W3C DOM 2 HTMLBodyElement interface doesn't define a focus method,
therefore it's likely to fail in most (if not all) browsers.

In particular, this.window.focus() fails in Opera 9.10 with an
"object not found", and windows.focus() succeeds in Opera 9.10, Firefox
2.02, and IE 7.

Entirely expected (allowing for the typo of "windows.focus" rather
than "window.focus").
 
R

Roger

RobG said:
this.window.focus()
When used in-line in the body tag, 'this' refers to the body element.
In a standard DOM, the body element doesn't have a window property;
trying to call a method of a non-existent property will result in a
script error.

window.focus()
This calls the focus method of the window object, which should work in
standards-compliant browsers though it may not have any effect. Some
browsers provide user configurable settings so that users can prevent
script from raising or lowering windows.

this.focus()
This will attempt to call the focus method of the body element. The
W3C DOM 2 HTMLBodyElement interface doesn't define a focus method,
therefore it's likely to fail in most (if not all) browsers.



Entirely expected (allowing for the typo of "windows.focus" rather
than "window.focus").

Thank you. If you write a book I will buy a copy.

The use for the above is to open a popup window with help info for a
complicated form. The intended use is for the user to read the help,
close the window and continue filling out the form.

In some cases, the user will click the parent window after reading the
help info and hide the help window. Since I am using named windows to
avoid users opening multiple copies of the same popup help window, some
means of giving focus to an old copy of the help window is necessary,
else the user will click the help link and nothing appears to happen.

My googling has found advice for yet another variation, that is to add
the focus call to the script opening the window. Something like:

url = 'someURL';
newwindow = window.open(url,'myhelp','height=600,....top=0');
newwindow.focus();

The above would appear to have no advantage over the <body onload...>
variation. Is there some obscure advantage to doing it this way --
would the help window gain focus faster if it takes a "long" time to
load? If the user's browser denies a script from lowering/raising
windows then all methods will fail equally, right?

Roger
 
S

scripts.contact

The use for the above is to open a popup window with help info for a
complicated form. The intended use is for the user to read the help,
close the window and continue filling out the form.

In some cases, the user will click the parent window after reading the
help info and hide the help window. Since I am using named windows to
avoid users opening multiple copies of the same popup help window, some
means of giving focus to an old copy of the help window is necessary,
else the user will click the help link and nothing appears to happen.

use divs (like on yahoo new account page) but if you have to use
window popups :
 

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,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top