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

D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
september.org>, Mon, 16 Aug 2010 21:16:51, Garrett Smith

Using the 12-hour clock after an ISO8601-formatted date is HORRIBLE.
And you have no way of knowing when I wrote it; you can only tell when I
finally committed it to the news transfer system.

It shouldn't; one should, however, be aware that the feature cannot be
expected to work.

That is ambiguous language; it does not of itself make clear whether it
means "will always not work" or "will not always work".

Remember that many readers of the FAQ were raised in countries where
English is taught, thoroughly, as a foreign language. It is not
sufficient to write so that, in your opinion, people like yourself would
perceive the intended, and only the intended, meaning.


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 intent expressed by the fictitious questioner is clearly that the
user will be presented with an unexpected result, i.e. no response. He
is not asking about providing a changed result. If nothing happens, the
user will click again more carefully, and then decide that the menu is
unavailable. That is the desired effect, though it is rendered of
little use if the user can find another way to do what he wanted.


Either you must make the answer match the question, or you must make the
question match the answer.

Even you do that, and you suppress the context menu and provide your
own menu,

The question does not ask about a new menu.
then it can still fail in some environments. Again, what about touch-
screen devices? No right-click there.

Then the questioner had nothing to change; but it remains necessary to
check that the fix for other devices has no adverse effect on such
touch-screen systems.
Right-click scripts were common and more popular around 2002 or so
(dynamicdrive.com had such inadvisable things).

Then it would be well to move the item from the FAQ to a "was in the
FAQ" document.
 
G

Garrett Smith

In comp.lang.javascript message<[email protected]
september.org>, Mon, 16 Aug 2010 21:16:51, Garrett Smith


Using the 12-hour clock after an ISO8601-formatted date is HORRIBLE.
And you have no way of knowing when I wrote it; you can only tell when I
finally committed it to the news transfer system.
There is apparently a way to configure Thunderbird to send different
date and time formats but I cannot find it now.
That is ambiguous language; it does not of itself make clear whether it
means "will always not work" or "will not always work".

The contextmenu event cannot be expected to be present.
Remember that many readers of the FAQ were raised in countries where
English is taught, thoroughly, as a foreign language. It is not
sufficient to write so that, in your opinion, people like yourself would
perceive the intended, and only the intended, meaning.

[...]
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 intent expressed by the fictitious questioner is clearly that the
user will be presented with an unexpected result, i.e. no response. He
is not asking about providing a changed result. If nothing happens, the
user will click again more carefully, and then decide that the menu is
unavailable. That is the desired effect, though it is rendered of
little use if the user can find another way to do what he wanted.

Suppressing the context menu provides very little deterrent to the user
saving images, much less to viewing the source code.

[...]
Then the questioner had nothing to change; but it remains necessary to
check that the fix for other devices has no adverse effect on such
touch-screen systems.
Those scripts were written in hopes of stopping users from saving
images/viewing source code.

Another reason for wanting to suppress the context menu is to prevent
default menu and provide a DHTML menu (based on a UL or DIV). For an
example, try context-clicking on the map portion of either
Then it would be well to move the item from the FAQ to a "was in the
FAQ" document.

Sounds like a fair judgment call. Unless I hear some objections, I'll
remove it.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
september.org>, Sat, 21 Aug 2010 01:27:09, Garrett Smith
The contextmenu event cannot be expected to be present.

That statement is clearly false. Whether or not anyone does expect it,
it is certainly possible to expect it. On the other hand, the context
menu is clearly either visible on the screen (present) or not visible on
the screen (not present).

Perhaps you mean something more like
"A context menu may or may not be available.".


But the question is not about the "context menu", which is a term that
the questioner may not be familiar with; it is about the right mouse
button, and should be answered only on that basis.


Suppressing the context menu provides very little deterrent to the user
saving images, much less to viewing the source code.

Those who asked about disabling the right click clearly believed it to
be useful to do so. It would be useful for, or rather against, all such
people.


Another reason for wanting to suppress the context menu is to prevent
default menu and provide a DHTML menu (based on a UL or DIV). For an
example, try context-clicking on the map portion of either
<http://www.bing.com/maps> or <http://maps.google.com>.

No. That would not be disabling the right click or even suppressing the
context menu. It would be replacing the context menu.


Sounds like a fair judgment call. Unless I hear some objections, I'll
remove it.

Since there may be a wish to read old items without relying on the
Wayback Machine, it would be better to move it to an "old parts" page,
itself divided into sections indicating roughly why they were removed.
 
D

David Mark

In comp.lang.javascript message <d14118b4-1f2b-4e13-ad62-f689a8c9ea88@o7
g2000prg.googlegroups.com>, Sat, 14 Aug 2010 16:18:35, David Mark
<[email protected]> posted:







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.



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

So the FAQ should then perpetuate such ignorance? Think yourself,
doc.
Advice in the FAQ should  reflect what generally works, with appropriate
warnings if it does not always work.

Isn't that exactly the sort of warning I suggested?
 
G

Garrett Smith

In comp.lang.javascript message<[email protected]
september.org>, Sat, 21 Aug 2010 01:27:09, Garrett Smith


That statement is clearly false. Whether or not anyone does expect it,
it is certainly possible to expect it. On the other hand, the context
menu is clearly either visible on the screen (present) or not visible on
the screen (not present).

OK. The contextmenu event must not be expected to be present.
Perhaps you mean something more like
"A context menu may or may not be available.".

That is a true statement, but it is not what I meant. I meant that
*suppressing* the context menu might not be possible.
But the question is not about the "context menu", which is a term that
the questioner may not be familiar with; it is about the right mouse
button, and should be answered only on that basis.

If the reason for asking about disable the right mouse button is to
suppress the context menu, then it is helpful to know what a context
menu is as well as how it may be triggered.


<http://en.wikipedia.org/wiki/Context_menu>

Explains that right-click is not the only way to trigger the result so
often seen by right click. For example, it mentions that on windows,
shift + F10 triggers a context menu.
Those who asked about disabling the right click clearly believed it to
be useful to do so. It would be useful for, or rather against, all such
people.

That is written in the FAQ already, in essence:
| Note that this will not prevent users from viewing your source code
| or copying images. To discourage copying, provide a copyright notice.
No. That would not be disabling the right click or even suppressing the
context menu. It would be replacing the context menu.

If on right-click, a user-defined menu is shown and the default context
menu is shown, that would be a problem. In that case, the developer
would want to prevent the latter.

If the user is intent on suppressing a context menu, it could be for
wanting to suppress one triggered from a click-and-hold action.

On macs, click-and-hold will trigger a context menu. This can be a
problem in a drag and drop implementation because the user can mousedown
to select the item, mousemove, while keeping the mouse button depressed,
and then *pop* comes the menu, during that mousemove, interfering with
the user's dragging action (at least visually).

This click-and-hold context menu preference is still available in Gecko
based browsers on macs. Thus, any function that is recognizes a
drag'n'drop action should take measures to suppress the context menu.

See also:
<http://kb.mozillazine.org/Ui.click_hold_context_menus>

And so if the questioner is asking about such things, then perhaps the
answer should reflect that. Or perhaps the question could be rephrased:

How do I prevent a context menu (right-click menu)?
Since there may be a wish to read old items without relying on the
Wayback Machine, it would be better to move it to an "old parts" page,
itself divided into sections indicating roughly why they were removed.
A list of removed items might be useful but it does not seem much worth
maintaining. The current answer is not worth archiving but might be
salvageable.
 
D

David Mark

About 1,580,000 results (0.16 seconds)




About 35,800 results (0.11 seconds)

Questions about "right click" and how it can be disabled use terminology
that is familiar to a neophyte.

But you've gone off-road with this line. The question the typical
neophyte wants answered is how to protect their source. In that
regard, they are only worried about one item on the context (as well
as the View) menu. As mentioned, there are many other ways to bring
up menus with a "Source" (or "View Source") item, so the scope of the
question is too narrow.

"How do I stop people from viewing the source of my page" would cover
all of them. Then you could explain about "right click menus" and the
rest of the lot (and how none of them can be reliably prevented).
 
G

Garrett Smith

On 2010-08-22 06:09 PM, David Mark wrote:>> > No, because the typical neophyte does not know that it is called
"context menu". [...]
http://www.google.com/search?rls=en&q="context+menu"&ie=utf-8&oe=...

About 35,800 results (0.11 seconds)
Correction:
About 3,770,000 results (0.13 seconds)

But what about preventing?
"prevent+context+menu": About 9,820 results

"prevent+right+click": About 138,000 results

"disable context menu": About 384,000 results

"disable right click": About 71,900 results

For "disable context menu", the first item in that list has the title
"How to disable right click context menu".
But you've gone off-road with this line. The question the typical
neophyte wants answered is how to protect their source. In that
regard, they are only worried about one item on the context (as well
as the View) menu. As mentioned, there are many other ways to bring
up menus with a "Source" (or "View Source") item, so the scope of the
question is too narrow.
The author might want to stop the user from saving images.
 
D

David Mark

On 2010-08-22 06:46 PM, David Mark wrote:
On 2010-08-22 06:09 PM, David Mark wrote:>>    >      No, because the typical neophyte does not know that it is called
   "context menu". [...]
http://www.google.com/search?rls=en&q="context+menu"&ie=utf-8&oe=...
About 35,800 results (0.11 seconds)

Correction:
About 3,770,000 results (0.13 seconds)

But what about preventing?
"prevent+context+menu": About 9,820 results

"prevent+right+click": About 138,000 results

"disable context menu": About 384,000 results

"disable right click": About 71,900 results

As soon as you take the wrong fork, you floor it. These results are
all irrelevant to the main question.
For "disable context menu", the first item in that list has the title
"How to disable right click context menu".

So what?
The author might want to stop the user from saving images.

And this presents you with a conundrum? See if you can figure out a
title that encompasses both concepts. Hint: they both revolve around
protecting content.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
september.org>, Sun, 22 Aug 2010 18:14:45, Garrett Smith
OK. The contextmenu event must not be expected to be present.

That would be interpreted by the semi-literate, whose presence here is
marked, as implying that it must only be expected to be absent. In
fact, it is sometimes present and sometimes absent; and wording used
should indicate that,

That is a true statement, but it is not what I meant. I meant that
*suppressing* the context menu might not be possible.

There we are; you concede that your language conveys the desired meaning
to yourself, but not to others.
If the reason for asking about disable the right mouse button is to
suppress the context menu, then it is helpful to know what a context
menu is as well as how it may be triggered.

If the FAQ subject line asks a question, then that question needs to be
answered. It may, for example, be the case that the reader has been
asked to maintain an existing site (written by someone who has more
knowledge, but not necessarily more wisdom) in which he has noted that
the right mouse button does not work when he wants it to. His real
question is then " How do I un-disable the right mouse button?", and it
will be helpful to state how it is likely to have been disabled.

After that, the merits of doing so can be indicated.

Remember : the FAQ maintainers chose the Subject questions; if it is not
appropriate to answer the question, then it should be replaced by an
answerable one.


If a FAQ entry need Wikipedia to be read, it should link to it.
That is written in the FAQ already, in essence:
| Note that this will not prevent users from viewing your source code
| or copying images. To discourage copying, provide a copyright notice.

But that is wrong. AISB, the programmer who asks the Subject question
MUST believe that suppressing right-click prevents the reader doing
something. Other readers believing the same will be prevented.

What you mean is "this will not make it impossible for users to view
your source code or to copy images".


And so if the questioner is asking about such things, then perhaps the
answer should reflect that. Or perhaps the question could be rephrased:

How do I prevent a context menu (right-click menu)?

That's rather limited. It occurs to me that I have, long ago and rather
easily, produced code to generate a new context menu (though I don't
recall how). That was using Delphi 3; it must have been done in the
GUI, as a unique menu-item string appears only in a machine-generated
TXT file. It would be to some extent useful to also answer for
JavaScript "How do I present a new context menu?", perhaps by giving a
link.


A list of removed items might be useful but it does not seem much worth
maintaining. The current answer is not worth archiving but might be
salvageable.

Maintenance would be negligible, albeit non-zero.
 
G

Garrett Smith

In comp.lang.javascript message<[email protected]
september.org>, Sun, 22 Aug 2010 18:14:45, Garrett Smith


That would be interpreted by the semi-literate, whose presence here is
marked, as implying that it must only be expected to be absent. In
fact, it is sometimes present and sometimes absent; and wording used
should indicate that,

I read that to mean that some individuals would read that as if by a
misplacing the "not", so instead of:

"The contextmenu event must not be expected to be present."

It would be misinterpreted by the semi-literate as:
"The contextmenu event must be expected to be not present."

- which has completely different meaning.

Expectations of a program are a mental step past the type of analysis.
An explanation of what can be expected to work seems more valuable than
just describing what works.
There we are; you concede that your language conveys the desired meaning
to yourself, but not to others.

Did you misinterpret "contextmenu event" as "context menu"?

I think the new entry should use "context menu" and "right-click menu",
as explained and the answer should be applicable to both to the casual
developer (hobbyist) who wishes to prevent users from copying source
code and to the developer who wishes to develop his own application
context menu.

[...]
After that, the merits of doing so can be indicated.

OK.

Remember : the FAQ maintainers chose the Subject questions; if it is not
appropriate to answer the question, then it should be replaced by an
answerable one.



If a FAQ entry need Wikipedia to be read, it should link to it.

I think so.
[...]
But that is wrong. AISB, the programmer who asks the Subject question
MUST believe that suppressing right-click prevents the reader doing
something. Other readers believing the same will be prevented.

What you mean is "this will not make it impossible for users to view
your source code or to copy images".

"Not prevent" seems more eloquent than "not make impossible"; the latter
seems more like a double negative to me.

| How do I prevent a context menu (right-click menu)?
|
| A context menu, often triggered by right-click, can be requested by
| the user in a few ways. For example, on windows, shift + F10 and on
| macs, click-and-hold. Input device hardware (mouse, tablet, etc) can
| also be reconfigured.
|
| Where supported, `document.oncontextmenu = function(){return false};`
| will suppress the default context menu on the document.
|
| Not all browsers provide context menus (iphone, for example, does
| not). Browsers that do provide context menus do not always provide a
| scriptable event for them and browsers that do provide a scriptable
| event may disallow scripts from disabling the context menu.
|
| Note that even when the context menu has been disabled, users will
| still be able to view your source code and copying images. To
| discourage copying, provide a copyright notice.
|
| See also:
| <http://en.wikipedia.org/wiki/Context_menu>
| <http://kb.mozillazine.org/Ui.click_hold_context_menus>
| said:
That's rather limited. It occurs to me that I have, long ago and rather
easily, produced code to generate a new context menu (though I don't
recall how). That was using Delphi 3; it must have been done in the
GUI, as a unique menu-item string appears only in a machine-generated
TXT file. It would be to some extent useful to also answer for
JavaScript "How do I present a new context menu?", perhaps by giving a
link.

That's about designing widgets. Prerequisites to that includes
understanding events and CSS. The idea is to capture the contextmenu
event, suppress the default contextmenu, and then show an element. A
document "mousedown" event can be used to hide the context menu.

Essentially developing your own menu entails using events and CSS.
 
E

Evertjan.

Garrett Smith wrote on 25 aug 2010 in comp.lang.javascript:
I read that to mean that some individuals would read that as if by a
misplacing the "not", so instead of:

"The contextmenu event must not be expected to be present."

It would be misinterpreted by the semi-literate as:
"The contextmenu event must be expected to be not present."

- which has completely different meaning.

Expectations of a program are a mental step past the type of analysis.
An explanation of what can be expected to work seems more valuable than
just describing what works.

As we KNOW that at least many mobile browsers and text browsers do not have
context menus, why not simply say:

=============
The "context menu", sometimes called "right-click menu",
is not available on some browsers, or if available,
does not always contain a copying command.

The "context menu" is by far not the only way of copying
of text and images.

In fact, preventing copying of text and images is impossible,
all information that is sent ["downloaded"] to a browser can be copied
and the only effective way to prevent that is not to put it on your page.
=============
 
G

Garrett Smith

"Not prevent" seems more eloquent than "not make impossible"; the latter
seems more like a double negative to me.

| How do I prevent a context menu (right-click menu)?
|
| A context menu, often triggered by right-click, can be requested by
| the user in a few ways. For example, on windows, shift + F10 and on
| macs, click-and-hold. Input device hardware (mouse, tablet, etc) can
| also be reconfigured.
|
| Where supported, `document.oncontextmenu = function(){return false};`
| will suppress the default context menu on the document.
|
| Not all browsers provide context menus (iphone, for example, does
| not). Browsers that do provide context menus do not always provide a
| scriptable event for them and browsers that do provide a scriptable
| event may disallow scripts from disabling the context menu.
|
| Note that even when the context menu has been disabled, users will
| still be able to view your source code and copying images. To
....................................................xxx
....and copy images.
[...]
Any objections to that replacing the existing entry? Keep in mind that
the answer is already long, so additions to that should be brief.
 
S

Scott Sauyet

Garrett said:
[...]
Any objections to that replacing the existing entry? Keep in mind that
the answer is already long, so additions to that should be brief.

No objection. It sounds like an improvement to me.
 
G

Garrett Smith

Garrett said:
[...]
Any objections to that replacing the existing entry? Keep in mind that
the answer is already long, so additions to that should be brief.

No objection. It sounds like an improvement to me.
OK, I'll be uploading that either today or tomorrow (my time zone, that is).
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
september.org>, Thu, 26 Aug 2010 18:22:55, Garrett Smith

You could say how to re-enable it; it's not obvious that the above
function does not replace one that actually gives the menu, but rather
prevents control being passed to the latter.

document.oncontextmenu = function() {alert("GO AWAY!"); return false}
 
G

Garrett Smith

In comp.lang.javascript message<[email protected]
september.org>, Thu, 26 Aug 2010 18:22:55, Garrett Smith

xxxxxxxxxxx^ suppress the

Can you explain why "suppress" is better here?

[...]
You could say how to re-enable it; it's not obvious that the above
function does not replace one that actually gives the menu, but rather
prevents control being passed to the latter.

Returning false from most event handlers will prevent the default action
associated with the event. In a "contextmenu" event, the default action
is displaying a context menu.

Should the entry explain that? The concept is not specific to
contextmenu events and returning false is not the only way to prevent
the default action. For most events, eventArg.preventDefault() (W3C
Model)/window.event.returnValue = false (IE Model) will have the same
effect.
 
E

Evertjan.

Dr J R Stockton wrote on 29 aug 2010 in comp.lang.javascript:
You could say how to re-enable it; it's not obvious that the above
function does not replace one that actually gives the menu, but rather
prevents control being passed to the latter.

document.oncontextmenu = function() {alert("GO AWAY!"); return false}

document.oncontextmenu = function() {alert("Now come back!");return true};

perhaps?
 

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
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top