Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to disable right click?

33 views
Skip to first unread message

Grant Ord

unread,
Sep 27, 2004, 2:03:07 PM9/27/04
to
How can I disble the right click behaviour.
I've seen a site that presents a popup that says 'this feature is disbled on
this site' when I right click - how is it done?
--
Thanks

Grant Ord

Kikoz

unread,
Sep 27, 2004, 2:26:23 PM9/27/04
to
<body oncontextmenu="alert('This feature ... blah');return false;">


"Grant Ord" <gran...@nospam.nospam> wrote in message
news:57A7D51F-0E28-48C0...@microsoft.com...

McKirahan

unread,
Sep 27, 2004, 2:31:25 PM9/27/04
to
"Grant Ord" <gran...@nospam.nospam> wrote in message
news:57A7D51F-0E28-48C0...@microsoft.com...

You'll soon be told by others that you can't disable the right-click and
that you can't hide your source code.

Here's two techniques which seem to work on some browsers; IE at least.

<html>
<head>
<title>noright1.htm</title>
</head>
<body oncontextmenu="return false">
</body>
</html>

This one tricks the user in to thinking that right-click is disabled. It
can be defeated by keeping the right mouse button down while pressing the
Enter key.

<html>
<head>
<title>noright2.htm</title>
<script type="text/javascript">
function click() {
if (event.button == 2) alert('This function has been disabled.')
}
document.onmousedown = click;
</script>
</head>
<body>
</body>
</html>

Keep checking back -- others will have a lot to say!

Just take a look at the post in comp.lang.javascript entitled "Disable
right-click without alert?".


Kikoz

unread,
Sep 27, 2004, 2:58:17 PM9/27/04
to
Just wanted to add that the whole idea of blocking right click is
absolutelly useless because user can disable javascript in any browser at
any moment. And, as a general rule, if you must hide you source than you
most likely have a much bigger problem with your development as a whole.


"McKirahan" <Ne...@McKirahan.com> wrote in message
news:10Z5d.166578$3l3.35668@attbi_s03...

Daniel Kirsch

unread,
Sep 28, 2004, 9:16:29 AM9/28/04
to
Kikoz wrote:
> Just wanted to add that the whole idea of blocking right click is
> absolutelly useless because user can disable javascript in any browser at
> any moment.

We are building web based applications where a right click opens the
application's context-menu. So there actually are situations where
blocking the default-behaviour might make sense.

Daniel

Evertjan.

unread,
Sep 28, 2004, 10:05:36 AM9/28/04
to
Daniel Kirsch wrote on 28 sep 2004 in
microsoft.public.scripting.jscript:

It seems polite to have the first option of that menu returning true, to be
able to use the rightclick functions, or to implement only alt-rightclick
to your menu:

<body
oncontextmenu="if(event.altKey){menu();return false};return true;'>

[I think there is more to it for non IE?]


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Randy Webb

unread,
Sep 29, 2004, 12:18:34 PM9/29/04
to

So you think that changing the default behavior, that people have become
adjusted to, "might make sense"? It doesn't.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

Kevin Yu [MSFT]

unread,
Oct 4, 2004, 4:43:40 AM10/4/04
to
Hi Grant,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Grant Ord

unread,
Oct 5, 2004, 5:13:03 PM10/5/04
to
Kevin

Sorry I did give feedback.

In the end I'm using all this lot and it seems to work.
I've also disabled dragging - outside of from boxes.
There is no need for it in my application and it prevents that horibble
highlighting you I get when I select inavertantly - I seem to suffer from it
with laptop touch pads and it drives me mad!

function oncontextmenuDocument() {
window.event.returnValue = false;
alert('This feature is not available on this site.');
}

function onmousedownDocument() {
if (window.event.button == 2) {
window.event.returnValue = false;
alert('This feature is not available on this site.');
}
}

function ondragstartDocument() {
with (window.event) {
if (srcElement.type) {
with (window.event.srcElement) {
if (!(type == 'text' || type == 'textarea')) {
returnValue = true;
return;
}
}
}
returnValue = false;
}
}

function onselectstartDocument() {
with (window.event) {
if (srcElement.type) {
with (window.event.srcElement) {
if (!(type == 'text' || type == 'textarea')) {
returnValue = true;
return;
}
}
}
returnValue = false;

Randy Webb

unread,
Oct 5, 2004, 6:10:01 PM10/5/04
to
Grant Ord wrote:
> Kevin
>
> Sorry I did give feedback.
>
> In the end I'm using all this lot and it seems to work.
> I've also disabled dragging - outside of from boxes.
> There is no need for it in my application and it prevents that horibble
> highlighting you I get when I select inavertantly - I seem to suffer from it
> with laptop touch pads and it drives me mad!

If the site is for an intranet, where you can control the setup of the
computers, then you can attempt to disable the mouse. Otherwise, you are
spinning your tail and no amount of script on the web will disable my
right mouse button. Mozilla and Opera both allow me to stop you from
disabling it.

chaitali pawar

unread,
Oct 15, 2004, 5:10:30 AM10/15/04
to

I tried the first option of using oncontextmenu in body tag.
It works everywhere except at the extreme edges.Means when I right click
around or near to the edges, the view source menu is popping out.
What should I do to prevent it?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Message has been deleted

Lasse Reichstein Nielsen

unread,
Oct 15, 2004, 12:17:03 PM10/15/04
to
chaitali pawar <chaital...@yahoo.com> writes:

> I tried the first option of using oncontextmenu in body tag.
> It works everywhere except at the extreme edges.Means when I right click
> around or near to the edges, the view source menu is popping out.
> What should I do to prevent it?

Put the oncontextmenu on the html element or remove margin on the body
element.

(And, as you have probably been told before, it's only something one
should do in controlled environments. For internet use, disableing the
context menu is just a big sign saying "Eirher I am clueless or I
don't want visitiors" :)

/L
--
Lasse Reichstein Nielsen - l...@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

JohnDpatriot

unread,
Oct 15, 2004, 12:15:56 PM10/15/04
to
Lee wrote:

> JohnDpatriot said:

>>Add this script to the top of the page (will only work with IE)
>
>
> I'm curious as to the circumstances in which hiding code from
> IE users only (and only if scripting is enabled) is useful.
>
In our organization we only allow IE and we use config scripts to ensure
that all IE clients are the same

chait

unread,
Oct 18, 2004, 6:30:27 AM10/18/04
to

Thanks a lot...Its working...
Hope it satisfies my client.

0 new messages