FAQ Topic - How do I disable the right mouse button? (2010-08-13)

F

FAQ server

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

The nonstandard `contextmenu` event is not widely supported.
Browsers that do support it may be configured to prevent scripts from
accessing that event.

Example:

<body oncontextmenu="return false">

Disables the context menu where supported. Note that this will not
prevent users from viewing your source code or copying images. To
discourage copying, provide a copyright notice.

<URL: http://msdn.microsoft.com/en-us/library/ms536914(VS.85).aspx>
<URL: https://developer.mozilla.org/En/DOM/Window.oncontextmenu>


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/
 
E

Evertjan.

FAQ server wrote on 13 aug 2010 in comp.lang.javascript:
To discourage copying, provide a copyright notice.

What nonsense.

Copying [as in pressing ctrl-C] does not infringe copyright.

Copying [part of] a webpage has as much to do with copyright,
as [the act of] giving birth has to do with birthright.
 
G

Garrett Smith

FAQ server wrote on 13 aug 2010 in comp.lang.javascript:


What nonsense.

What nonsense?
Copying [as in pressing ctrl-C] does not infringe copyright.
Did you misconstrue?

Is the entry written ambiguously? I suppose "unauthorized reproduction"
is better than "copying".
 
D

David Mark

What nonsense?

How about the title? How many times do you have to be told that it is
not always the "right" mouse button that initiates a context menu. In
fact, some mice have but one button.
Copying [as in pressing ctrl-C] does not infringe copyright.

Did you misconstrue?

Doesn't appear so. The comment about copyright notices is silly too.
 
L

Lasse Reichstein Nielsen

David Mark said:
How about the title? How many times do you have to be told that it is
not always the "right" mouse button that initiates a context menu. In
fact, some mice have but one button.

So what? It's still a frequently asked question.
Doesn't appear so. The comment about copyright notices is silly too.

Not really.
You can't technically prevent copying.
You can't morally prevent copying that is lawful.
So, the only copying that you can do anything about is unlawful
copying, which is what the copyright notice is there to discourage.

/L
 
D

David Mark

So what? It's still a frequently asked question.

There should be some explanation in the FAQ about the many ways in
which it is the wrong question. There may be no right mouse button,
there are other ways to invoke a context menu, there are ways besides
the context menu to copy content and view the source, etc.

And this leads to many other similar questions which are not featured
in the FAQ. Best to come up with a better title that encompasses more
than just the "right mouse button" question.
Not really.

It is too! :)
You can't technically prevent copying.
You can't morally prevent copying that is lawful.
So, the only copying that you can do anything about is unlawful
copying, which is what the copyright notice is there to discourage.

It's a stretch for a question in a JS FAQ titled "How do I disable the
right mouse button".
 
G

Garrett Smith

How about the title? How many times do you have to be told that it is
not always the "right" mouse button that initiates a context menu. In
fact, some mice have but one button.

The title is not what Evertjan was commenting on.

The reason it says "right button" is that is the common thing that the
green developer will think in terms of.

Sure, a context menu can be triggered by control-click on mac or
specially configured mouse; but that does not mean the title of the
entry needs changing.
 
D

David Mark

The title is not what Evertjan was commenting on.

Did I say it was? Or did you read that into it in your own inimitable
"style"?
The reason it says "right button" is that is the common thing that the
green developer will think in terms of.

Among a dozen other things related to "protecting" their source code.
Sure, a context menu can be triggered by control-click on mac or
specially configured mouse; but that does not mean the title of the
entry needs changing.

You need changing.
 
E

Evertjan.

Garrett Smith wrote on 13 aug 2010 in comp.lang.javascript:
FAQ server wrote on 13 aug 2010 in comp.lang.javascript:


What nonsense.

What nonsense?
Copying [as in pressing ctrl-C] does not infringe copyright.
Did you misconstrue?
eh?

Is the entry written ambiguously? I suppose "unauthorized reproduction"
is better than "copying".

There is no authorisation necessary for copying what is on the web.

Only the publishing could be unlawful without authorisation,
and then only if it is a work of art or craft, like a programma,
data are never under copyright,
nor is the manner of a programme's invocation.

So if you don't want your work to be copied,
there is only one simple and effective method:

Do not publish it.
 
E

Evertjan.

Garrett Smith wrote on 14 aug 2010 in comp.lang.javascript:

The nonsense is that "copyright" on the web is NOT about copying,
as all webpages are copied [ to the cashe ] to be seen.

The Dutch word for "copyright" is "auteursrecht",
a better word, since this is about the rights of the autor.

Preventing copying to the clipboard has nothing to do with preventing
copyright infringement.

Indeed, also the "right button" could be the wrong button,
if buttons are swapped, say by a lefthanded mouse user.
The title is not what Evertjan was commenting on.

Indeed. one should comment on what one quotes.

If one comments on the subject, repeat the subject as a quote,
or at least use explicit reference to such subject line.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
, Thu, 12 Aug 2010 23:00:02, FAQ server <[email protected]> posted:


The nonstandard `contextmenu` event is not widely supported.

Right Click is supported, using XP sp3, in IE8, Firefox 3.0.19, Opera
10.10, Safari 5.0, Chrome 5.0. That seems reasonably wide to me, even
if no other browser and no non-MS operating system support it, which
seems unlikely.
Browsers that do support it may be configured to prevent scripts from
accessing that event.

Example:

<body oncontextmenu="return false">

Making a setting on a particular page is not configuring the browser.

Something more like "For some/many/most browsers, including in the page
'<body oncontextmenu="return false">' will inhibit any response to
clicking the right mouse button on the body element." would be better.

Note that this will not
prevent users from viewing your source code or copying images.

It will prevent those users who believe it to be the only way.
 
D

David Mark

Right Click is supported, using XP sp3, in IE8, Firefox 3.0.19, Opera
10.10, Safari 5.0, Chrome 5.0.  That seems reasonably wide to me, even
if no other browser and no non-MS operating system support it, which
seems unlikely.

"Right Click"?!
Making a setting on a particular page is not configuring the browser.

You missed the point, doc. You can configure some browsers (e.g.
Opera) to ignore such handlers/listeners.
Something more like "For some/many/most browsers, including in the page
 '<body oncontextmenu="return false">'  will inhibit any response to
clicking the right mouse button on the body element." would be better.

I don't know that it would be better, but it is certainly a lousy
suggestion (for numerous reasons).

For one, virtually all browsers render the HTML element (exception is
IE in quirks mode and IE < 6). Imagine if the body has margins.

For two, configuring the OS mouse settings for left-handed users will
swap the left and right mouse button behaviors. Furthermore, the
context menu can often be triggered with a keystroke. So the mention
of "clicking the right mouse button" is not a very good description.

Obviously, the question that the typical neophyte wants answered is
how to disable the context menu (which is still a bad question, but at
least closer to what they have in mind).
It will prevent those users who believe it to be the only way.

Not really (see point #1).
 
A

amin arab

<body oncontextmenu="return false">

this not good way for this work in IE and Opera and chrome . if width
of body not equal to 100% then some browser can cancel only part pf
page
that putted element and so i offer this code :

<head>
<script type="text/javascript" >
function mischandler(){
return false;
}

function mousehandler(e){
//var myevent = (isNS) ? e : event;
var myevent = e || event;
//var eventbutton = (isNS) ? myevent.which : myevent.button;
var eventbutton = myevent.which || myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}

document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
</script>
</head>

http://www.computerhope.com/j20.htm (with little change to have not
dependency to check browser).
test it on other OS . this maybe will work.

thanks
amin
:)
 
G

Garrett Smith

In comp.lang.javascript message<[email protected]

Right Click is supported, using XP sp3, in IE8, Firefox 3.0.19, Opera
10.10, Safari 5.0, Chrome 5.0. That seems reasonably wide to me, even
if no other browser and no non-MS operating system support it, which
seems unlikely.

Indeed support has been growing. But it cannot be relied on. Support may
depend on the OS and touch screen devices cannot be expected to support it.

How about changing "widely" to "universally"?

Seems sufficient to me. How a browser is configured depends on the
browser; there isn't one way.

For example, in Firefox (with English settings), go to "Tools > Options
Content Tab", next to "Enable JavaScript" click "Advanced". A modal
dialog will appear with the heading "Allow scripts to:". Uncheck
"Disable or replace context menus".
Making a setting on a particular page is not configuring the browser.

So the example follow its preceding paragraph might present the possible
interpretation that the example demonstrates what is explained (about
configuring the browser). Did I get that right?
Something more like "For some/many/most browsers, including in the page
'<body oncontextmenu="return false">' will inhibit any response to
clicking the right mouse button on the body element." would be better.
An explanatory paragraph is a good idea.

Replace "some/many/most" with "where supported" (because that wording
includes browsers that support the event but have been configured to
disallow it).

Focusing on "right button" in the subject is ok, but the answer should
not pretend that that is the only wayt to rigger a context menu.
Describing that the code inhibits response to right click might is not
misleading. Instead, the answer should use "suppress the context menu"
instead of in place and perhaps change "inhibit" to "suppress" and
replace "any response" to "the context menu". Even when the right click
is the context menu click, then it still triggers a series of events.
Thus, it does not inhibit any response (it suppresses the context menu).

An alternative:

"Where supported, `<body oncontextmenu="return false">` will suppress
the the default context menu on the `BODY` element.

If the terminology is unfamiliar to an inexperienced beginner, then he
is at least left with a line of code that he can quickly try out.
It will prevent those users who believe it to be the only way.
I don't have statistical data on the
users-who-believe-right-click-is-the-only-way-to-view-source group (much
less demographics of that ilk), but I suspect it's pretty dang low.
Users tend to click on the application menu items when they want to do
something and don't know how.
 
G

Garrett Smith

In comp.lang.javascript message<[email protected]

Right Click is supported, using XP sp3, in IE8, Firefox 3.0.19, Opera
10.10, Safari 5.0, Chrome 5.0. That seems reasonably wide to me, even
if no other browser and no non-MS operating system support it, which
seems unlikely.


Making a setting on a particular page is not configuring the browser.

Something more like "For some/many/most browsers, including in the page
'<body oncontextmenu="return false">' will inhibit any response to
clicking the right mouse button on the body element." would be better.

That's still invalid HTML. Why didn't I notice earlier? And so if the
solution is invalid HTML, then perhaps it would be better to use an
event handler property example.

function returnFalse() {
return false;
}

document.documentElement.oncontextmenu = returnFalse;

I've not tested it. The approach can't be relied on.
 
D

Dr J R Stockton

In comp.lang.javascript message <055954b2-67bd-4d2f-8271-82342c0b04b6@x2
0g2000pro.googlegroups.com>, Fri, 13 Aug 2010 18:14:42, David Mark
How about the title? How many times do you have to be told that it is
not always the "right" mouse button that initiates a context menu. In
fact, some mice have but one button.

But the people who actually ask the question do not know that. It is
important that FAQ section Subjects, whether or not they match the
wording of the Subject of a particular article, should be meaningful to
those who are looking for answers.

And it should be obvious that, because disabling the context menus is of
limited use, the answer to the question will be sought by those of
limited knowledge.
 
G

Garrett Smith

In comp.lang.javascript message<[email protected]
[...]
Describing that the code inhibits response to right click might is not
misleading. Instead, the answer should use "suppress the context menu"
instead of in place and perhaps change "inhibit" to "suppress" and
replace "any response" to "the context menu". Even when the right click
is the context menu click, then it still triggers a series of events.
Thus, it does not inhibit any response (it suppresses the context menu).

Sorry that didn't sense.

What I meant to say was the answer should use "suppress the context
menu" instead of "inhibit any response".
An alternative:

"Where supported, `<body oncontextmenu="return false">` will suppress
the the default context menu on the `BODY` element.
That's no good because it's invalid HTML.

| Where supported, `document.oncontextmenu = function(){return false};`
| will suppress the default context menu on the document.
 
D

Dr J R Stockton

In comp.lang.javascript message <d14118b4-1f2b-4e13-ad62-f689a8c9ea88@o7
g2000prg.googlegroups.com>, Sat, 14 Aug 2010 16:18:35, David Mark
"Right Click"?!

I tested with a Right Click, so I reported it as such without making
assumptions about what anything else does. "Right Click" means to use
the (current) right mouse button, and it is that which the Subject
rightly refers to.

You missed the point, doc. You can configure some browsers (e.g.
Opera) to ignore such handlers/listeners.

Think (again, if possible) : only a small proportion of Web page users
know about that, and a smaller proportion do it.

Advice in the FAQ should reflect what generally works, with appropriate
warnings if it does not always work.

For example, the expression NaN + NaN does not always give NaN .

I don't know that it would be better, but it is certainly a lousy
suggestion (for numerous reasons).

For one, virtually all browsers render the HTML element (exception is
IE in quirks mode and IE < 6). Imagine if the body has margins.
Irrelevant.

For two, configuring the OS mouse settings for left-handed users will
swap the left and right mouse button behaviors.

By convention, the right button (the one referred to in the Subject
line) is then on the left.

Furthermore, the
context menu can often be triggered with a keystroke. So the mention
of "clicking the right mouse button" is not a very good description.


The Subject question concerns the right mouse button.

Obviously, the question that the typical neophyte wants answered is
how to disable the context menu (which is still a bad question, but at
least closer to what they have in mind).

No, because the typical neophyte does not know that it is called
"context menu".

Not really (see point #1).

If they try what they believe to be the only way, and it fails to work,
they will of necessity give up. Remember, it is the neophyte thinking
that matters, not yours.

It is a great pity that you can type faster than you think.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
september.org>, Sun, 15 Aug 2010 11:53:17, Garrett Smith
On 2010-08-14 01:04 PM, Dr J R Stockton wrote:

An explanatory paragraph is a good idea.

Replace "some/many/most" with "where supported" (because that wording
includes browsers that support the event but have been configured to
disallow it).

No. Your "where supported" is strictly accurate; but unhelpful; it
carries, for many readers, an implication that support is uncommon.
ISTM that support is general, but not necessarily universal; the FAQ
wording should reflect that.


It's not a question that I recall being asked very often here.
 
G

Garrett Smith

In comp.lang.javascript message<[email protected]
september.org>, Sun, 15 Aug 2010 11:53:17, Garrett Smith


No. Your "where supported" is strictly accurate; but unhelpful; it
carries, for many readers, an implication that support is uncommon.

It shouldn't; one should, however, be aware that the feature cannot be
expected to work.
ISTM that support is general, but not necessarily universal; the FAQ
wording should reflect that.

Try disabling the context menu as per the explanation of how to do that
in Firefox. Such capability cannot be expected.

For Internet Explorer, the administrator may disable the context menu by
using a Registry Entry:
| NoBrowserContextMenu:
| Disables the right-click shortcut menu on a Web page.
<http://support.microsoft.com/kb/823057>

If the user wants to use right click, he will. He will probably expect
that when he does that, he gets the browser context menu (with the
things like "back", "view source", "open link in new tab" or any number
of other things that he has learned about what should appear in the menu
when he right clicks.

The user will not expect anything new from any site in general (nothing
beyond what his browser provides in that menu) and so if you want to
change the user's expectation by suppressing the context menu and
providing your own (based on a UL or DIV) -- and you can do that in some
browsers -- you'll need to provide strong clues and indicators to the
user. Otherwise, the user will apply his expectations or preconceptions
(or whatever you want to call it) of what right-click is about. Such
clues might include instructions and heuristics. Again, it is possible
-- and, for more desktop-like webapp, especially a closed intranet app
-- not unthinkable.

Even you do that, and you suppress the context menu and provide your own
menu, then it can still fail in some environments. Again, what about
touch-screen devices? No right-click there.
It's not a question that I recall being asked very often here.

Right-click scripts were common and more popular around 2002 or so
(dynamicdrive.com had such inadvisable things).
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top