By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,843 Members | 864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,843 IT Pros & Developers. It's quick & easy.

window.onclick in IE and Gecko agents

P: n/a
Why window.onclick isn't fired in IE and is fired on Gecko agents ?

<html onclick="alert('Event is now at the HTML element.')">
<head>
<title>Event Bubbles</title>
<script type="text/javascript">
function init() {
document.onclick = docEvent;
window.onclick = winEvent

document.body.onclick = docBodEvent;
alert(document == window);
}
function winEvent() {
alert("Event is now at the window object level.");
}
function docEvent() {
alert("Event is now at the document object level.");
}
function docBodEvent() {
alert("Event is now at the BODY element.");
}
</script>
</head>
<body onload="init()">
<h1>Event Bubbles</h1>
<hr />
<form onclick="alert('Event is now at the FORM element.')">
<input type="button" value="Button 'main1'" name="main1"
onclick="alert('Event started at Button: ' + this.name)" />
</form>
</body>
</html>

Dec 2 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Ok i know the answer:
See the table below:
Event Bubbling Variations for Listing
Event Handler Location WinIE4+ MacIE4+ NN6+/Moz1+/Safari
button yes yes yes
form yes yes yes
body yes yes yes
HTML yes no yes
document yes yes yes
window no no yes

Dec 2 '05 #2

P: n/a
Luke Matuszewski wrote:
Ok i know the answer:
See the table below:
A reference to where the table came from would be helpful, or did you
make it yourself?

Event Bubbling Variations for Listing
Event Handler Location WinIE4+ MacIE4+ NN6+/Moz1+/Safari
button yes yes yes
form yes yes yes
body yes yes yes
HTML yes no yes
document yes yes yes
window no no yes

HTML 4.01 does not specify an onclick attribute for the HTML element,
the body element would be a more suitable location.

--
Rob
Dec 2 '05 #3

P: n/a

RobG napisal(a):
Luke Matuszewski wrote:
Ok i know the answer:
See the table below:
A reference to where the table came from would be helpful, or did you
make it yourself?

It comes from JavaScript Bible , 5th Ed by Danny Goodman (if i were
younger i would say :O :O :O .... ;-) ).

HTML 4.01 does not specify an onclick attribute for the HTML element,
the body element would be a more suitable location.


It refers not to <html> element (tag) but i guess the most of html
elements which has %events entity in DTD.

Dec 3 '05 #4

P: n/a
OF TOPIC

While searching in 1 ebook in Acrobat Reader 7 while writing this
post(switched from Acrobat to window where i was writting this post
when he stopped searching on first found result and i fired searching
again from page where the result was - 400) and then opening another
ebook and thus switched to Acrobat again a saw that it made no progress
because it continued from page 400 and even starded searching in new
opened ebook at page 1 !
I made few more switches to see it again - page 400 was always the
staring point in Acrobat for first ebook and page 1 for ebook 2 (no
progress in searching in 'background') - yep i think it is a bug :-)
try it your self (the bug is only when i open second ebook - which
triggers search in this ebook from 1 page :)

Dec 3 '05 #5

P: n/a
Luke Matuszewski wrote:
RobG napisal(a):

[...]
A reference to where the table came from would be helpful, or did you
make it yourself?


It comes from JavaScript Bible , 5th Ed by Danny Goodman (if i were
younger i would say :O :O :O .... ;-) ).


Goodman's book is not held in high regard, you might be better to not
use it at all. :-x

HTML 4.01 does not specify an onclick attribute for the HTML element,
the body element would be a more suitable location.


It refers not to <html> element (tag) but i guess the most of html
elements which has %events entity in DTD.


Not sure what you mean. Your original post had code with an onclick
attribute in an HTML tag, Goodman's table (as posted) seemed to suggest
that it was OK to added them. The HTML element has no events, so no
attempt should be made to to add them. If that is what Goodman's book
suggests or advises, then it's a good example of why you shouldn't use it.

Despite what the specification says, some browsers may support event
attributes being added to the HTML element. But that does not make it
OK to do so, as it can't be expected to be reliable across all browsers
conforming to HTML 4. There are a great many more browsers than those
in the table and mobile devices will likely grow the number hugely.
--
Rob
Dec 4 '05 #6

P: n/a

RobG napisal(a):
Luke Matuszewski wrote:
RobG napisal(a): [...]
A reference to where the table came from would be helpful, or did you
make it yourself?


It comes from JavaScript Bible , 5th Ed by Danny Goodman (if i were
younger i would say :O :O :O .... ;-) ).


Goodman's book is not held in high regard, you might be better to not
use it at all. :-x

HTML 4.01 does not specify an onclick attribute for the HTML element,
the body element would be a more suitable location.


It refers not to <html> element (tag) but i guess the most of html
elements which has %events entity in DTD.


Not sure what you mean. Your original post had code with an onclick
attribute in an HTML tag, Goodman's table (as posted) seemed to suggest
that it was OK to added them. The HTML element has no events, so no
attempt should be made to to add them. If that is what Goodman's book
suggests or advises, then it's a good example of why you shouldn't use it.

Ok as i read you reply i saw the onclick event in <html> element -
which is not good practice as HTML 4.01 spec states that <html> element
has no onclick event...

Thanks for answer, and sorry for example which is not valid HTML as
w3c.org states...

My experience on reading different books shows that in those books
there is only a suggestion on how things work and if they don't refer
to specifications it is ok - but that i have learned from experience.
Worst books refer to specification and provide material/examples that
are not valid when comparing what specification says.

Best way is to know specification or has quick access to them (as for
eg. to the Internet for checking w3c.org HTML specs) and then support
our knowledge by reading books.

Despite what the specification says, some browsers may support event
attributes being added to the HTML element. But that does not make it
OK to do so, as it can't be expected to be reliable across all browsers
conforming to HTML 4. There are a great many more browsers than those
in the table and mobile devices will likely grow the number hugely.


Yes, i agree and sorry for my (well Danny Goodman was first) example
provided from his book.

My way to learn things has evolved as i was misguided by many different
books... and i am in stage where i can say i do following:
- i learn/know the specification and how to search them;
- i read (now only fragments) of books which reveals some asspects of
knowledge and how this knowledge deals with real world (so eg. how it
works on different user agents), and while reading i especially try to
catch fragments which is not valid against specification;
- i try to remeber things that are specification valid and how they
work in real world today, cause only then i can say that maybe it will
work on the future and maybe they will work on not standards compilant
future devices - as producents of such devices will probably try to not
break compatibility which older versions (versions of devices which
work today);

BR.
Luke

Dec 4 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.