Disable rightclick in Opera?

231 views
Skip to first unread message

Nicky Castermans

unread,
Dec 6, 2002, 2:58:04 AM12/6/02
to
Is it possible to disable the right mouse button click in Opera?
And maybe also the dragevent? So that u can't select any text?

Thanks for any help


Richard Cornford

unread,
Dec 6, 2002, 4:08:25 AM12/6/02
to
Nicky Castermans wrote in message ...

>Is it possible to disable the right mouse button click in Opera?
>And maybe also the dragevent? So that u can't select any text?


No it is not. Opera's designers consider the context menu to be an
important usability feature and seem to be determined not to make it
disableable (and many Opera users support that decision). As to
selection, current versions (up to 7) do not seem to have any awareness
of selections exposed to JavaScript (although, I may have just missed
them in O7) so they cannot be influenced by scripting.

Richard.


Hans Börjesson

unread,
Dec 6, 2002, 3:56:01 AM12/6/02
to

"Nicky Castermans" <ncast...@pi.be> wrote in message
news:asplab$cds$1...@reader08.wxs.nl...

> Is it possible to disable the right mouse button click in Opera?
> And maybe also the dragevent? So that u can't select any text?
>
> Thanks for any help


I don't have Opera installed but maybe it supports the oncontextmenu. It
could for example be placed in the body tag. It will (if supported) prevent
RMB.

<body oncontextmenu="return false;">

The user can of course bypass this if he/she want for example by disble
javascript.

Regards
/Hans


Nicky Castermans

unread,
Dec 6, 2002, 10:38:27 AM12/6/02
to
The oncontextmenu feature doesnt work, I allready tried.
Thanks for the reply anyway


"Hans Börjesson" <ha...@NOSPAMvendimo.com> wrote in message
news:aspoee$63b$1...@yggdrasil.utfors.se...

DU

unread,
Dec 6, 2002, 7:30:55 AM12/6/02
to

I think it should be possible to disable the right mouse button on a
mousedown or click in Opera 7 as mousedown and click are cancelable.
http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-MouseEvent-button
says:
"The values for button range from zero to indicate the left button of
the mouse, one to indicate the middle button if present, and two to
indicate the right button. For mice configured for left handed use in
which the button actions are reversed the values are instead read from
right to left."

<script type="text/javascript">
<!--
function VerifyIfRightClick(evt)
{
if(evt.button == 2) {evt.preventDefault();};
}

function init()
{
if(document.addEventListener)
{document.addEventListener("mousedown", VerifyIfRightClick, true);};
}
-->
</script>
<head>
<body onload="init();" ...>

The above code has not been tested in Opera 7.

I strongly recommend you don't disable right click in Opera or any
browser unless you have a very good reason to ... and I can not imagine
one you could give. If you can limit such disabling to just one or a few
elements, it would be less damaging for the usability. Remember that
there are many commands available in the contextmenu... If you're trying
to avoid people from copying images on your page, then you're losing
your time and you're most likely going to annoy a lot of your visitors.

DU

Richard Cornford

unread,
Dec 10, 2002, 10:09:07 AM12/10/02
to
DU wrote in message <2M0I9.49$0q6....@news.ca.inter.net>...

>Nicky Castermans wrote:
>> Is it possible to disable the right mouse button click in Opera?
>> And maybe also the dragevent? So that u can't select any text?
<snip>

>I think it should be possible to disable the right mouse button on a
>mousedown or click in Opera 7 as mousedown and click are cancelable.

<snip>


>I strongly recommend you don't disable right click in Opera or any
>browser unless you have a very good reason to ... and I can not imagine

>one you could give...
<snip>

The theory is sound but Opera Version 7.0 (Build 2345) would not play
ball. The context menu appeared anyway. I added an alert to the
beginning of 'VerifyIfRightClick' to verify that it was being called and
the context menu appeared on a right-click and when the context menu
closed the alert appeared. I would conclude that it is too late to
affect the context menu with 'preventDefault' (or any return values) at
that stage.

Still, I don't think that you or I will be at all unhappy that Opera
continues to discourage people from messing with the context menu in an
internet context.

Richard.


DU

unread,
Dec 11, 2002, 5:43:00 PM12/11/02
to
Richard Cornford wrote:
> DU wrote in message <2M0I9.49$0q6....@news.ca.inter.net>...
>
>>Nicky Castermans wrote:
>>
>>>Is it possible to disable the right mouse button click in Opera?
>>>And maybe also the dragevent? So that u can't select any text?
>
> <snip>
>
>>I think it should be possible to disable the right mouse button on a
>>mousedown or click in Opera 7 as mousedown and click are cancelable.
>
> <snip>
>
>>I strongly recommend you don't disable right click in Opera or any
>>browser unless you have a very good reason to ... and I can not imagine
>>one you could give...
>
> <snip>
>
> The theory is sound but Opera Version 7.0 (Build 2345) would not play
> ball. The context menu appeared anyway. I added an alert to the
> beginning of 'VerifyIfRightClick' to verify that it was being called and
> the context menu appeared on a right-click and when the context menu
> closed the alert appeared. I would conclude that it is too late to
> affect the context menu with 'preventDefault' (or any return values) at
> that stage.
>

Hmm... it depends. Mousedown in capture propagation happens before the
click event and a right click must be fired to generate a context menu.
So, it should not be too late.
Most of the time the users want to prevent right click on images and
there, it is even more easier (I mean editing a script; not preventing
copy of image). Because you can deal with the event at the document
level on its capture mode before it propagates/reaches the intended
target, the images.

> Still, I don't think that you or I will be at all unhappy that Opera
> continues to discourage people from messing with the context menu in an
> internet context.
>
> Richard.
>
>

I agree Richard.
Btw, on this precise topic, I just found a bug in Opera 7 (build 2349).
The W3C gives left = 0, middle = 1 and right = 2 for the button
property. But O7 does not seem to honor this standard.

DU

Vitalii Vasianovych

unread,
Nov 16, 2021, 5:48:27 AM11/16/21
to
Reply all
Reply to author
Forward
0 new messages