The moose likes HTML, CSS and JavaScript and the fly likes Bemused event question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Bemused event question" Watch "Bemused event question" New topic

Bemused event question

Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
This might be a totally stupid question, I'm not a javascript expert but I wonder if someone could elighten me on something.

I'm trying to use the <SCRIPT FOR = object EVENT = oncontextmenu> construct in IE.

Now you can specify <body oncontextmenu="myfunction()"> in HTML and the MSDN Link seems to me to imply that oncontextmenu is an event associated with the body object so naively I assumed

<SCRIPT FOR = document.body EVENT = oncontextmenu> would work! Does it %&*"! you have to use <SCRIPT FOR = document EVENT = oncontextmenu>

Similarly you can specify onunload in an HTML <BODY> tag but you have to use <SCRIPT FOR = window EVENT = onunload> to get it to work!!! I know one is a tag and the other a DOM object but I expected some sort of correlation.

Am I missing a piece of wondrous logic somewhere, how do I work out which DOM object I should use, i.e the one that initiates the event/gets the event bubbled to it???

Thanks to anyone who can shine some light on this

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

My only advice would be to avoid the IE-only proprietary mechansims and limit yourself to W3C standards.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Bemused event question
jQuery in Action, 3rd edition