This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 60752

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

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
subject: Bemused event question
Similar Threads
Clearing httpsession on window close, techniques?
Disable Right Click,View source and save as
serious problem about script loading
catching page change or browser close
Multiple &ltSCRIPT&gt tags in a page