What is wrong with Focus on Firefox?

W

WH

<html>
<head>
<style type="text/css">
html, body
{
overflow: hidden;
}
</style>
</head>
<body onload="showit()" leftMargin="0" rightMargin="0" topMargin="0"
marginwidth="0"
marginheight="0">

<iframe id="myframe" src="http://www.yahoo.com" width=100% height=100%
FRAMEBORDER="0"></iframe>


<script type="text/javascript" language="javascript1.2">
<!--
function showit() {
myframe.focus();
//some other codes here

}

-->
</script>
</body></html>

In IE, works perfectly, in firefox, not automatically focus.
 
W

WH

Where's the "myframe" variable defined and initialized? Ah, it's the ID
of an element, not a variable - then use a standard way to get a handle
to the element, not an IE-ism:)

Check the FAQ 4.41:

<URL:http://jibbering.com/faq/#FAQ4_41>


No, notwrking. Test this

<html>
<head>
<style type="text/css">
html, body
{
overflow: hidden;
}
</style>

</head>
<body onload="document.getElementById('myframe').focus();" leftMargin="0"
rightMargin="0" topMargin="0" marginwidth="0" marginheight="0">

<iframe id="myframe" src="http://www.yahoo.com" width=100% height=100%
FRAMEBORDER="0"></iframe>

</body></html>

it is not auto focuced even with ById
 
Y

Yann-Erwan Perio

WH wrote:

[iframe focusing]
it is not auto focuced even with ById

You're right, sorry.

Firstly, I've referred you to something not applicable in the first
place; the correct way to focus a frame is to give the frame a name, and
then use
frames["frameName"].focus();

Secondly, I thought that the iframe could be focused, but I cannot
manage to do it in Mozilla, even with the correct way and files from the
same domain. I'm beginning to think this isn't doable, others might give
us more insight.


Regards,
Yep.
 
L

Lasse Reichstein Nielsen

WH said:
No, notwrking. Test this
<body onload="document.getElementById('myframe').focus();" leftMargin="0"
rightMargin="0" topMargin="0" marginwidth="0" marginheight="0">

<iframe id="myframe" src="http://www.yahoo.com" width=100% height=100%
FRAMEBORDER="0"></iframe>

Two points:

The "focus" function exists on window objects, not (i)frame objects.
Using "getElementById" will give you the iframe object, not the window
object inside it. Sadly, there is no standard way to access that window
(some browsers has the non-standard "frameElement.contentWindow",
others only have "frameElement.contentDocument"). To access frames
by name, the best way is to use the frames collection (available as
a global variable, i.e, a property of the window object):
frames['myframe'].focus;

Also, your iframe contains content from another domain. The security
settings might, or might not, prevent you from interacting with the
embedded page's window. Whether it works might depend on whether the
embedded page has begun loading or not, when you access it.

/L
 
W

WH

Two points:
The "focus" function exists on window objects, not (i)frame objects.
Using "getElementById" will give you the iframe object, not the window
object inside it. Sadly, there is no standard way to access that window
(some browsers has the non-standard "frameElement.contentWindow",
others only have "frameElement.contentDocument"). To access frames
by name, the best way is to use the frames collection (available as
a global variable, i.e, a property of the window object):
frames['myframe'].focus;

Also, your iframe contains content from another domain. The security
settings might, or might not, prevent you from interacting with the
embedded page's window. Whether it works might depend on whether the
embedded page has begun loading or not, when you access it.

IE works every time. Mozzila never works. Here is the code based on
frams.name, still not working.

<html>
<head>
<style type="text/css">
html, body
{
overflow: hidden;
}
</style>

</head>
<body onload="frames.['myframe'].focus();" leftMargin="0" rightMargin="0"
topMargin="0" marginwidth="0" marginheight="0">

<iframe id="myframe" src="http://www.yahoo.com" width=100% height=100%
FRAMEBORDER="0"></iframe>

</body></html>
 
L

Lasse Reichstein Nielsen

WH said:
frames['myframe'].focus;
....
IE works every time. Mozzila never works. Here is the code based on
frams.name, still not working.
<body onload="frames.['myframe'].focus();" leftMargin="0" rightMargin="0"

I can see it doesn't work. There is a "." too many.
What error message does the browser give you?

Have you validated your HTML?
<iframe id="myframe" src="http://www.yahoo.com" width=100% height=100%

I would probably add
name="myframe"
as well, so you have both "id" and "name". It won't hurt, and it might
even work in some older browsers as well.

/L
 
W

WH

WH said:
...
frames['myframe'].focus;
...
IE works every time. Mozzila never works. Here is the code based on
frams.name, still not working.
<body onload="frames.['myframe'].focus();" leftMargin="0"
rightMargin="0"

I can see it doesn't work. There is a "." too many.
What error message does the browser give you?

Have you validated your HTML?
<iframe id="myframe" src="http://www.yahoo.com" width=100% height=100%

I would probably add
name="myframe"
as well, so you have both "id" and "name". It won't hurt, and it might
even work in some older browsers as well.

Thanks. It is working. after I removed . after frames and added name=
However it is not working in Opera yet. Opera 7.2
 

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

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top