Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > this.window.focus() vs. window.focus() vs. this.focus()

Reply
Thread Tools

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

 
 
Roger
Guest
Posts: n/a
 
      03-08-2007
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
 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      03-08-2007
On Mar 8, 3:32 pm, Roger <crosseyedpeng...@cox.net> wrote:
> 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").


--
Rob

 
Reply With Quote
 
 
 
 
Roger
Guest
Posts: n/a
 
      03-08-2007
RobG wrote:
> On Mar 8, 3:32 pm, Roger <crosseyedpeng...@cox.net> wrote:
>> 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").
>
>
> --
> Rob
>


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
 
Reply With Quote
 
scripts.contact@gmail.com
Guest
Posts: n/a
 
      03-08-2007
On Mar 8, 9:39 am, Roger <crosseyedpeng...@cox.net> wrote:
> 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 :
--
url='someUrl'
newWin=window.open(url,"helpWin","features")
newWin.window.focus

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57