Mozilla Firefox compatibility problem

S

Simon Wigzell

I have the following in my webpage:

<body onresize=CenterIt(); onMouseMove=mouseCheck(event);>

CenterIt and mouseCheck are my own javascript functions. Works fine for IE
and Opera, doesn't even go into the function for Firefox or Netscape. Is
there a different way to assign functions to events that will be understood
by "all" browsers? Thanks!
 
R

Richard Cornford

Simon said:
I have the following in my webpage:

<body onresize=CenterIt(); onMouseMove=mouseCheck(event);>

Is there a different way to assign functions to events that
will be understood by "all" browsers? Thanks!

Try writing formally valid HTML.

Richard.
 
T

Tim Slattery

Simon Wigzell said:
I have the following in my webpage:

<body onresize=CenterIt(); onMouseMove=mouseCheck(event);>

CenterIt and mouseCheck are my own javascript functions. Works fine for IE
and Opera, doesn't even go into the function for Firefox or Netscape. Is
there a different way to assign functions to events that will be understood
by "all" browsers? Thanks!

IMHO your HTML syntax is wrong and I'm rather surprised that IE
understands it. Try:

<body onresize="CenterIt();" onmousemove="mouseCheck(event);">
 
S

Simon Wigzell

Oh thank you so much! You are so kind and so helpfull! Now I know how what I
did wrong! Now I can solve my problem! You are so wonderfull!

Can I send you some money as a reward for your deep insight and wisdom?
 
R

Richard Cornford

Simon Wigzell wrote:
Oh thank you so much! You are so kind and so helpfull!
Now I know how what I did wrong! Now I can solve my
problem! You are so wonderfull!
<snip>

If you validated your HTML the validator would tell you what was wrong
with it and you wouldn't have to ask.

Richard.
 
G

Gérard Talbot

Tim Slattery wrote :
IMHO your HTML syntax is wrong and I'm rather surprised that IE
understands it. Try:

<body onresize="CenterIt();" onmousemove="mouseCheck(event);">

There is no onresize event handler for the body element in HTML 4.01: so
that too is invalid.
The window.event property is MSIE-specific. MSIE does not support DOM 2
Events interface. So both Firefox and Netscape should reply in their
javascript console that "event is an undefined object".

Gérard
 
G

Gérard Talbot

Simon Wigzell wrote :
Oh thank you so much! You are so kind and so helpfull! Now I know how what I
did wrong! Now I can solve my problem! You are so wonderfull!

Can I send you some money as a reward for your deep insight and wisdom?

You may find Richard's answer irritating and frustrating but I assure
you that the very first thing to do when facing a layout or error or a
problem of some sort is to make sure that the markup code is well-formed
and valid and that the CSS code is valid and does not generate parsing
errors. Often, the source of problems is there or starts there.

So:
- onresize is not a valid attribute for body element; you would possibly
want the resize event to be registered on the window object instead
- event is a proprietary object in MSIE 5+
- MSIE 6 does not support DOM 2 Events attributes and methods

Crossbrowser DOM Scripting: Event Handlers
http://www.scottandrew.com/weblog/articles/cbs-events

There you go.

Gérard
 
J

Jim Ley

Tim Slattery wrote :

There is no onresize event handler for the body element in HTML 4.01: so
that too is invalid.

You've not got enough information to say that, he may be using a
doctype, or internal subset with an onresize attribute for body. The
brackets problems are not solvable in a document you can serve as
text/html.

Jim.
 
L

Lasse Reichstein Nielsen

Gérard Talbot said:
Tim Slattery wrote :
The window.event property is MSIE-specific. MSIE does not support DOM
2 Events interface. So both Firefox and Netscape should reply in their
javascript console that "event is an undefined object".

No. Inside an intrinsic event handler, all current browsers make the
triggering event available as a variable called "event". IE just uses
a global variable, the other browsers use a local one (I guess Opera
might do both :).

So, try it before you bash it :)
/L
 
G

Gérard Talbot

Jim Ley wrote :
You've not got enough information to say that, he may be using a
doctype, or internal subset with an onresize attribute for body.

Well, I was referring to HTML 4.01. And I always assume that (a standard
doctype) as default when someone post.
If I remember correctly, in such case (internal error correction
mechanism), Mozilla-based browsers and MSIE assign the resize event to
the window object by default.
I wanted to point out the invalid attribute.

The
brackets problems are not solvable in a document you can serve as
text/html.

Jim.

I don't understand that last part: what brackets problems? You mean
missing quote " signs?.. ok then :) Yes, missing the quotes is decisive.

Cheers,

Gérard
 
J

Jim Ley

Jim Ley wrote :

Well, I was referring to HTML 4.01. And I always assume that (a standard
doctype) as default when someone post.

You can't do that however, especially as the W3 standard doctypes are
not the only ones that user agents support, particularly onresize on
body which is supported by the majority of user agents.
If I remember correctly, in such case (internal error correction
mechanism), Mozilla-based browsers and MSIE assign the resize event to
the window object by default.

This is not "internal error correction" it's the documented behaviour
for the user agents.

Jim.
 
G

Gérard Talbot

Jim Ley a écrit :
You can't do that however, especially as the W3 standard doctypes are
not the only ones that user agents support,

Well, unless specified otherwise by a poster, I will assume a standard
doctype, not a custom or oddball doctype decl.


particularly onresize on
body which is supported by the majority of user agents.

onresize seems to be supported by the body element but it's the window
object that gets+handles the resize event in such case.
onresize usage on the body element is not valid. Not according to HTML
4.01 specs.

Gérard
 
G

Gérard Talbot

Lasse Reichstein Nielsen a écrit :
No. Inside an intrinsic event handler, all current browsers make the
triggering event available as a variable called "event". IE just uses
a global variable, the other browsers use a local one (I guess Opera
might do both :).

So, try it before you bash it :)
/L


Hello Lasse,

Ok, I will try it.

I tried to contact you several weeks ago. I wrote this document

http://developer-test.mozilla.org/en/docs/window.open

(at least its original, initial version)
and added your article as a reference. Just thought you wanted to know.

Gérard
 
J

Jim Ley

onresize seems to be supported by the body element but it's the window
object that gets+handles the resize event in such case.

So, that's completlely irrelevant.
onresize usage on the body element is not valid.

Please understand, that it's potentially completely valid, even with
an HTML 4.01 strict doctype declaration, you can just add it into the
internal subset. The reason I'm discussing this is that your post was
misleading, the onresize in body is well supported, almost certainly
the preferred way to declare onresize, and well documented in Mozilla
FireFox, as well as other user agents.
Not according to HTML 4.01 specs.

We have no reason to believe the OP was using HTML 4.01

Jim.
 
S

Simon Wigzell

Simon Wigzell said:
I have the following in my webpage:

<body onresize=CenterIt(); onMouseMove=mouseCheck(event);>

CenterIt and mouseCheck are my own javascript functions. Works fine for IE
and Opera, doesn't even go into the function for Firefox or Netscape. Is
there a different way to assign functions to events that will be
understood by "all" browsers? Thanks!
I have resolved my problem. This is what I have to do:

<body>
<script language="JavaScript" type="text/javascript">

checkmouse = 0;
checkresize = 0;

document.onmousemove = mouseCheck;
function mouseCheck()
{
if (checkmouse == 0)
{
alert("Mouse Moved");
checkmouse = 1;
}
}
window.onresize = resizeCheck;
function resizeCheck()
{
if (checkresize == 0)
{
alert("Resize");
checkresize = 1;
}
}

</script>
</body>

Now couldn't one of you have just answered my question and told me this
instead of all this jibber jabber????

Thanks anyway!
 
G

Gérard Talbot

Jim Ley wrote :
So, that's completlely irrelevant.

I do not understand why you say it's completely irrelevant.

How often does one resize the body element without using the resizing
window handles of a browser window?
I do not know of a single occurence or webpage where one resizes the
body element without resizing the browser window; theoretically, that
should be doable, possible.

<body onresize="...">
is invalid markup code. That markup code is supported by many browsers
because the onresize event handler gets handled by the window, not the
body element. That's why I referred to internal browser error mechanism.
Please understand, that it's potentially completely valid, even with
an HTML 4.01 strict doctype declaration, you can just add it into the
internal subset.

I understand that it's potentially completely valid. But it's not valid
with a standard HTML 4.01 doctype declaration. onresize attribute is not
listed anywhere in the HTML 4.01 spec.:
http://www.w3.org/TR/html4/index/attributes.html
onresize attribute for body element is not even listed as deprecated either.
How often do you see web authors/web pages using a custom DTD or a
modified DTD or an extended DTD?
How often do you see people saying in this newsgroup that they use a
custom DTD or a modified DTD or an extended DTD?

<body asdf="ghjk">
is invalid markup code. But then if one has to always add that this is
in cases where a custom DTD or extended/modified DTD is not used, then
posting in this newsgroup can/should become very long, tediously
explicit, excessively exact, miserably cautious, mono-maniacally detailed.

The reason I'm discussing this is that your post was
misleading,

I said word for word this:
"There is no onresize event handler for the body element in HTML 4.01:
so that too is invalid."
and you're saying my post was misleading.


the onresize in body is well supported, almost certainly
the preferred way to declare onresize,

Well that way should not be the preferred way to declare and use the
onresize attribute. In HTML 4.01. When using an official W3C doctype. In
a non-modified DTD. In a non-custm DTD. In a very vast majority of
webpages on the web.
Is that the way we should always post from now on?

and well documented in Mozilla

Ok go ahead: bring the url at mozilla.org where it says that <body
onresize="..."> is valid, ok, good enough, preferable or whatever.

as well as other user agents.
We have no reason to believe the OP was using HTML 4.01

Jim.

Above 99% of all webpages on the web and above 99% of people posting in
this newsgroup do not use a custom DTD nor an extended/modified DTD.
Without any url from the OP, without any sufficient chunk of relevant
code pasted from the OP, without any kind of useful data from the OP
post from the OP, why shouldn't I assume he is using HTML 4.01? standard
HTML 4.01 that is. Non-modified HTML 4.01 DTD.

Gérard
 
J

Jim Ley

<body onresize="...">
is invalid markup code.

Stop repeating that fact, it's not invalid, it may be invalid in some
documents, but it's not invalid in all.
I understand that it's potentially completely valid. But it's not valid
with a standard HTML 4.01 doctype declaration.

It can still be, consider the internal subset.
How often do you see web authors/web pages using a custom DTD or a
modified DTD or an extended DTD?
Lots.

the onresize in body is well supported, almost certainly

Well that way should not be the preferred way to declare and use the
onresize attribute.

Sure it should, it's the method that most works.
Is that the way we should always post from now on?

We should post the most sensible advice, and for registering an
onresize event <body onresize is appropriate. You could against argue
that it's not, but if your only argument is about validity, then it's
not a good one, as it can be perfectly valid.
and well documented in Mozilla

Ok go ahead: bring the url at mozilla.org where it says that <body
onresize="..."> is valid, ok, good enough, preferable or whatever.

eh? it's documented do onresize site:mozilla.org in your favourite
search engine and read the documentation.
Above 99% of all webpages on the web and above 99% of people posting in
this newsgroup do not use a custom DTD nor an extended/modified DTD.

No 99% of all the web pages are invalid, a minority of some boiler
plate gibberish at the top they don't understand, but that's not
particularly relevant.

<body onresize is the most appropriate, if your work flows involve
valid HTML, then there are trivial scenarios you can use, as anyone
who's validating their mark-up should know about.

Jim.
 
K

knocte

Jim Ley escribió:
eh? it's documented do onresize site:mozilla.org in your favourite
search engine and read the documentation.

Keeping your "absolute strict" way for stating things, your post is
misleading because... do all search engines (or, at least, all search
engines which are favourite for, at least again, one person in the
world) support the "site:" rule syntax?

Of course you were referring to Google above all. And, if I insert those
terms on google, I don't find anything about "<body onresize="...">". On
the other hand, I see that the first result title is "window.onresize".

Regards,

knocte

--
 

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,777
Messages
2,569,604
Members
45,235
Latest member
Top Crypto Podcasts_

Latest Threads

Top