Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Frames do not have .focus() method?

3 views
Skip to first unread message

Pete

unread,
Dec 6, 1996, 3:00:00 AM12/6/96
to

Several people have been asking lately about giving particular frames focus
upon loading. Several folks have suggested the following snippet:

onload"parent.frames[0].focus();"

However, when I try to use it I get told by both IE3.0 and NN3.0 that the
method is not handled by the object. In fact going to
http://home.netscape.com/eng/mozilla/3.0/handbook/javascript/index.html
does not reveal any indication that focus() is a method of window or frames
or parent.

But, Laura Lemay's Web Workshop: JavaScript does say on page 182 "You can
also use the methods setTimeout(), clearTimeout(), blur, and focus()." in
reference to Frame Object Properties, Events, and Methods. Her books are
extremely well received, but is she wrong in this case as well as several
posters?

So what's the story? Has anyone successfully gotten frame focus to work?
I'm stuck.

--Peter Mancini

Ed Smith

unread,
Dec 6, 1996, 3:00:00 AM12/6/96
to Pete

Pete wrote:
>
> Several people have been asking lately about giving particular frames focus
> upon loading. Several folks have suggested the following snippet:
>
> onload"parent.frames[0].focus();"
^
I'm not sure if this is just typo in the message but the equals sign is
missing. Other than that, I not sure why you had a problem with NN3.0
(unless the page is being viewed without frames, when there is no
frames[0]
object). MSIE 3.0 is somewhat compatible with NN2.0, but window.focus()
was added in NN3.0.

>
> However, when I try to use it I get told by both IE3.0 and NN3.0 that the
> method is not handled by the object. In fact going to
> http://home.netscape.com/eng/mozilla/3.0/handbook/javascript/index.html

Actually they use a few of NN2.0's pages and add links for any NN3.0
upgrades. From their page:

focus method

Changed in Navigator 3.0 <= link to NN3.0 information for
window.focus()

Gives focus to the specified object.

Syntax

1. passwordName.focus()
2. sel...


Hope This Helps
Ed Smith
cc: comp.lang.javascript pman...@lynx.neu.edu

Pete

unread,
Dec 6, 1996, 3:00:00 AM12/6/96
to

Actually, it is a typo in the post and not in the code I used. Perhaps
this will help make it clearer: I am not sure if the JS code belongs in the
document with the frameset or in one of the frame documents. For example
would I have:

<HTML>
<FRAMESET "*,*">
<FRAME name=foo src=foo.htm>
<FRAME name=bar src=bar.htm onLoad="parent.bar.focus();">
</FRAMESET>
</HTML>

or would bar.htm have

<HTML>
<BODY onLoad="parent.bar.focus();">
This is bar.htm
</BODY>
</HTML>

I tried both and didn't have any luck. Both the frameset and the source
documents are generated from CGIs, if that makes a difference.

Also, is there a specific version of NN3.0 (b6, 3.01, etc.) that implements
the focus() method for frames?

Thanks for the help so far. Still stumped, but trying hard...
--Pete

Ed Smith <e...@edbo.com> wrote in article <32A850...@edbo.com>...


> Pete wrote:
> > onload"parent.frames[0].focus();"
> ^
> I'm not sure if this is just typo in the message but the equals sign is
> missing. Other than that, I not sure why you had a problem with NN3.0
> (unless the page is being viewed without frames, when there is no
> frames[0]
> object). MSIE 3.0 is somewhat compatible with NN2.0, but window.focus()
> was added in NN3.0.

Daniel Robino

unread,
Dec 6, 1996, 3:00:00 AM12/6/96
to

Pete wrote:
>
> Actually, it is a typo in the post and not in the code I used. Perhaps
> this will help make it clearer: I am not sure if the JS code belongs in the
> document with the frameset or in one of the frame documents. For example
> would I have:
>
> <HTML>
> <FRAMESET "*,*">
> <FRAME name=foo src=foo.htm>
> <FRAME name=bar src=bar.htm onLoad="parent.bar.focus();">
> </FRAMESET>
> </HTML>
>
> or would bar.htm have
>
> <HTML>
> <BODY onLoad="parent.bar.focus();">
> This is bar.htm
> </BODY>
> </HTML>
>
> I tried both and didn't have any luck. Both the frameset and the source
> documents are generated from CGIs, if that makes a difference.
>
> Also, is there a specific version of NN3.0 (b6, 3.01, etc.) that implements
> the focus() method for frames?

The following is from Netscapes documentation:

focus

<<Changed.>>

The focus method is now a method of the frame and window objects. The
focus method gives focus to a window or
frame. Giving focus brings a window forward in most windowing systems.

Syntax

The following syntax has been added for the focus method:

frameReference.focus()
windowReference.focus()

Parameters

frameReference is a valid way of referring to a frame, as described in
the Frame object.

windowReference is a valid way of referring to a window, as described in
the Window object.

Method of

Frame
Window

--
Daniel Robino
DR Computer
http://www.ntplx.net/~drobino

Gavin Lambert

unread,
Dec 8, 1996, 3:00:00 AM12/8/96
to

In article <01bbe3af$23f102c0$ede521ce@jubilex>, pman...@lynx.neu.edu says...

>would I have:
>
><HTML>
><FRAMESET "*,*">
><FRAME name=foo src=foo.htm>
><FRAME name=bar src=bar.htm onLoad="parent.bar.focus();">
></FRAMESET>
></HTML>
>
>or would bar.htm have
>
><HTML>
><BODY onLoad="parent.bar.focus();">
>This is bar.htm
></BODY>
></HTML>
>
>I tried both and didn't have any luck. Both the frameset and the source
>documents are generated from CGIs, if that makes a difference.

The second syntax seems much more likely.

Here's a stab in the dark... try calling window.focus() rather than
parent.bar.focus()...

I'm not sure, however, that it will work in the case of an onLoad though... an
onLoad for a frame is called immediately after _the_frame_ finishes initial
loading (ie. before any images etc) and you have no control over what order the
frames load in.

So what could happen is this:

1. the frame 'bar' loads & receives focus.
2. bar.onload is called, which sets the focus to itself.
3. the frame 'foo' loads & receives focus.

So you end up with 'foo' having focus in the end. At other times, however,
they load in a completely different order & 'bar' will receive the focus.

My favourite trick for waiting until all frames are loaded before doing
something is this:

In each frame I define a variable like so:

var frameLoaded = 1;

Then in the onLoad routine of the 'bar' frame I'd call pageStartup().

pageStartup() is defined as follows:

function pageStartup() {
if(top.foo.frameLoaded && top.blah.frameLoaded && top.blah2.frameLoaded)
window.focus();
else
setTimeout('pageStartup()', 100);
}

That will keep the routine checking until all the frames have loaded up. Note
that images may still be loading at this point, but I don't think that affects
the frame focus.

Hope this helps.

-----
Gavin Lambert
uec...@geocities.com
http://www.geocities.com/SiliconValley/Heights/1987


JP

unread,
Dec 9, 1996, 3:00:00 AM12/9/96
to

"Pete" <pman...@lynx.neu.edu> wrote:

>Several people have been asking lately about giving particular frames focus
>upon loading. Several folks have suggested the following snippet:
>
>onload"parent.frames[0].focus();"

the focus() function is NS3+ specific, being JavaScript 1.1, and is
used in the following manners:

i) windowreference.focus()
ii) framereference.focus()

The snippet above should read:

<BODY ..... onLoad="parent.frames[0].focus()">

>However, when I try to use it I get told by both IE3.0 and NN3.0 that the
>method is not handled by the object. In fact going to
>http://home.netscape.com/eng/mozilla/3.0/handbook/javascript/index.html

>does not reveal any indication that focus() is a method of window or frames
>or parent.

The focus() function is described in the What's New in Navigator 3.0
section of the JavaScript Guide at Netscape's Web Site:

http://home.netscape.com/eng/mozilla/3.0/handbook/javascript/atlas.html

Good luck,

Jason.


-----------------------------------------------
Jason Phillips Melbourne, Australia
j...@ozemail.com.au

Director, !Impressions! Web Design

http://www.ozemail.com.au/~jbp/impressions/

** A Member of the HTML Writer's Guild **
-----------------------------------------------

Ed Smith

unread,
Dec 10, 1996, 3:00:00 AM12/10/96
to Pete

Pete wrote:
> I tried both and didn't have any luck. Both the frameset and the source
> documents are generated from CGIs, if that makes a difference.

Shouldn't make a different, are the scripts online? Maybe we can take
a look at them to if we can find the trouble.


>
> Also, is there a specific version of NN3.0 (b6, 3.01, etc.) that implements
> the focus() method for frames?

Came out in release 3.0, though I don't know which beta implemented it,
(or may have had bugs with it), probably was b1 but I'm not sure.

Ed Smith

0 new messages