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

FAQ Topic - How do I disable the right mouse button?

P: n/a
-----------------------------------------------------------------------
FAQ Topic - How do I disable the right mouse button?
-----------------------------------------------------------------------

The oncontextmenu intrinsic event is the only safe and reliable
method. Of the other approaches often presented, most depend on
an alert box interrupting the process and rarely work. Note that
oncontextmenu is a non-standard event and is not supported on
all browsers.
` <body oncontextmenu="return false"`
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
The FAQ workers are a group of volunteers. The sendings of these
daily posts are proficiently hosted by www.pair.com.

Sep 3 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
FAQ server wrote:
The oncontextmenu intrinsic event
As I have pointed out in my still unanswered e-mail to both current FAQ
maintainers about 20 days ago (along with other suggestions and comments),
that wording is wrong. `oncontextmenu' is a proprietary event handler,
not an intrinsic event as defined by and in the HTML 4.01 Specification:

http://www.w3.org/TR/html401/interac...ts.html#events
is the only safe and reliable method.
As I also have pointed out, because it is proprietary and not standardized,
it runs the risk of being not well supported, if supported at all, and so it
is not a safe and reliable method at all.
Of the other approaches often presented, most depend on
an alert box interrupting the process and rarely work. Note that
oncontextmenu is a non-standard event
It is a non-standard (i.e. proprietary) event *handler*. The corresponding
event would be `contextmenu'. It is just that the MSDN Library is unable to
make that important distinction to date (when MS begins to implement DOM
Level 2+ Events, they will finally have to.) In that sense, the HTML 4.01
Specification which uses the same (wrong) terminology has been updated by
the W3C DOM Level 2 Events Specification as indicated by the included note
in the aforementioned subsection of HTML 4.01:

http://www.w3.org/TR/DOM-Level-2-Events/
and is not supported on all browsers.
There is the all-too-obvious contradiction to the above statements.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Sep 4 '07 #2

P: n/a
Thomas 'PointedEars' Lahn said the following on 9/3/2007 8:14 PM:
FAQ server wrote:
>The oncontextmenu intrinsic event

As I have pointed out in my still unanswered e-mail to both current FAQ
maintainers about 20 days ago (along with other suggestions and comments),
that wording is wrong.
20 days ago was about the time I changed the email address in the FAQ to
the current one. If you sent an email to the old address then it would
explain why I haven't received it. If you sent it to cl****@comcast.net
then I honestly do not know why I have not received it unless it didn't
have FAQ in the Subject line of the email. If you would, please forward
it or re-send it to cl****@comcast.net and make sure the Subject Line
has FAQ in it so that the spam filter doesn't catch it by mistake.

Although personally, I would prefer that comments regarding the FAQ -
and its contents - be posted to the group so that it can be reviewed and
commented on by the group.

<snip>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
FAQ Notes: http://www.jibbering.com/faq/faq_notes/faq_notes.html
ECMAScript Language Specification via FAQ2.6
Sep 4 '07 #3

P: n/a
Thomas 'PointedEars' Lahn said the following on 9/3/2007 8:14 PM:
FAQ server wrote:
>The oncontextmenu intrinsic event
My personal vote: The entry is wrong from start to finish. The question
being:

"How do I disable the right mouse button?"

And the only technically correct answer can only be:

"You can't".

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 4 '07 #4

P: n/a
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 9/3/2007 8:14 PM:
>FAQ server wrote:
>>The oncontextmenu intrinsic event

My personal vote: The entry is wrong from start to finish. The question
being:

"How do I disable the right mouse button?"

And the only technically correct answer can only be:

"You can't".
My personal vote is to keep

<body oncontextmenu="return false">

--
Bart

Sep 4 '07 #5

P: n/a
In comp.lang.javascript message <4q*********************@giganews.com>,
Tue, 4 Sep 2007 08:51:52, Randy Webb <Hi************@aol.composted:
>Thomas 'PointedEars' Lahn said the following on 9/3/2007 8:14 PM:
>FAQ server wrote:
>>The oncontextmenu intrinsic event

My personal vote: The entry is wrong from start to finish. The question
being:

"How do I disable the right mouse button?"

And the only technically correct answer can only be:

"You can't".
A most irresponsible suggestion. Of course a script can disable the
right mouse button, or at least prevent it showing the usual menu. One
condition is sufficient, though probably not entirely necessary : that
the browser be IE6 running in XP sp2.

For me, <body oncontextmenu="return false" disables it in IE6,
but not in Opera 9.23.

Therefore, an acceptable answer giving that code must state clearly that
it works in some but not all browsers.

Consider -
User, viewing page : The right mouse button does not now work!
Adviser, reading FAQ : It cannot be disabled; it must be broken.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Sep 4 '07 #6

P: n/a
FAQEditor said the following on 9/4/2007 8:43 AM:
Thomas 'PointedEars' Lahn said the following on 9/3/2007 8:14 PM:
>FAQ server wrote:
>>The oncontextmenu intrinsic event

As I have pointed out in my still unanswered e-mail to both current FAQ
maintainers about 20 days ago (along with other suggestions and
comments),
that wording is wrong.

20 days ago was about the time I changed the email address in the FAQ to
the current one. If you sent an email to the old address then it would
explain why I haven't received it. If you sent it to cl****@comcast.net
then I honestly do not know why I have not received it unless it didn't
have FAQ in the Subject line of the email. If you would, please forward
it or re-send it to cl****@comcast.net and make sure the Subject Line
has FAQ in it so that the spam filter doesn't catch it by mistake.
Have you tried to resend that email? I have not yet received any from you.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
FAQ Notes: http://www.jibbering.com/faq/faq_notes/faq_notes.html
ECMAScript Language Specification via FAQ2.6
Sep 6 '07 #7

P: n/a
FAQEditor wrote:
FAQEditor said the following on 9/4/2007 8:43 AM:
>Thomas 'PointedEars' Lahn said the following on 9/3/2007 8:14 PM:
>>FAQ server wrote:
The oncontextmenu intrinsic event
As I have pointed out in my still unanswered e-mail to both current FAQ
maintainers about 20 days ago (along with other suggestions and
comments),
that wording is wrong.
20 days ago was about the time I changed the email address in the FAQ to
the current one. If you sent an email to the old address then it would
explain why I haven't received it. If you sent it to cl****@comcast.net
then I honestly do not know why I have not received it unless it didn't
have FAQ in the Subject line of the email. If you would, please forward
it or re-send it to cl****@comcast.net and make sure the Subject Line
has FAQ in it so that the spam filter doesn't catch it by mistake.

Have you tried to resend that email? I have not yet received any from you.
Sorry, I'm currently too busy doing my (RL) job.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Sep 7 '07 #8

P: n/a
On Sep 4, 9:39 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Dr J R Stockton said the following on 9/4/2007 6:16 PM:
In comp.lang.javascript message <4qWdnQ4jxLgdyUDb4p2d...@giganews.com>,
Tue, 4 Sep 2007 08:51:52, Randy Webb <HikksNotAtH...@aol.composted:
Thomas 'PointedEars' Lahn said the following on 9/3/2007 8:14 PM:
FAQ server wrote:
The oncontextmenu intrinsic event
My personal vote: The entry is wrong from start to finish. The question
being:
"How do I disable the right mouse button?"
And the only technically correct answer can only be:
"You can't".
Right. It's the wrong question. It should be "How do I disable the
context menu."
>
A most irresponsible suggestion.

It isn't a "suggestion", it is fact. You can not disable my right mouse
button. Although you are welcome to try to prove me wrong.
Of course a script can disable the right mouse button,

No it doesn't. Nor can it. Remember that this discussion got started
because Thomas wanted it semantically/technically correct.
or at least prevent it showing the usual menu.

It doesn't do that either. Reverse the mouse buttons and you can still
get that menu if you disable the right mouse button (try it).
This is not true. Software applications get the correct logical
button, regardless of which physical button generated the event. I
just tested it with my context function. I would have been shocked if
it failed for IE as the event is "contextmenu" and there is no need to
detect the button in JavaScript. It didn't break in the other agents
that use mouseup and button detection either. For the record, I have
tested in IE5, IE5.5, IE6, IE7, Firefox 2, Netscape 9, Opera 9 and
Safari Beta on Windows and all work with this logic in a contextmenu/
mouseup handler:

e = e || global.event;
if ((e.which == 3 || e.button & 4) || e.type == 'contextmenu') ...

If memory serves me right, at least one non-IE browser (Opera I think)
supports the contextmenu event. So you have to deal with cases where
both events fire. I believe the above works for Mac's as well,
despite the fact that most (all?) have a single mouse button. IIRC,
to generate a context click requires holding the button for a few
seconds. Certainly it should work in Mac IE if it supports the
contextmenu event.

There just is no one-line solution that is suitable for a FAQ entry on
how to disable the context menu. And there is definitely no answer
for how to disable a physical right click (or even a logical context
ckick.)

And I think it should be noted that it is insane to handle context
clicks unless you implement a custom context menu (and it is a very
rare case where that is appropriate.)

Oct 6 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.