Disable right click 
Author Message
 Disable right click
Hi,

On my page I use the following script to disable the right mouse click
The question : Is it possible that the user sees nothing when (s)he
rightclicks instead of an alertbox ?

<script language=JavaScript>
var message="Function Disabled"
function click(e)
{
 if (document.all)
 {
  if (event.button==2||event.button==3)
  {
   alert(message); // --> I want these alerts gone !
   return false;
  }
 }
 if (document.layers)
 {
  if (e.which == 3)
  {
   alert(message); // --> I want these alerts gone !
   return false;
  }
 }

Quote:
}

if (document.layers)
{
 document.captureEvents(Event.MOUSEDOWN);
Quote:
}

document.onmousedown=click;
</script>



Sun, 09 Mar 2003 03:00:00 GMT  
 Disable right click

just return false


Quote:
> Hi,

> On my page I use the following script to disable the right mouse click
> The question : Is it possible that the user sees nothing when (s)he
> rightclicks instead of an alertbox ?

> <script language=JavaScript>
> var message="Function Disabled"
> function click(e)
> {
>  if (document.all)
>  {
>   if (event.button==2||event.button==3)
>   {
>    alert(message); // --> I want these alerts gone !
>    return false;
>   }
>  }
>  if (document.layers)
>  {
>   if (e.which == 3)
>   {
>    alert(message); // --> I want these alerts gone !
>    return false;
>   }
>  }
> }
> if (document.layers)
> {
>  document.captureEvents(Event.MOUSEDOWN);
> }
> document.onmousedown=click;
> </script>



Sun, 09 Mar 2003 03:00:00 GMT  
 Disable right click
I've tried it before, but that doesn't work --> The user sees the
contextmenu again !


Quote:
> just return false



> > Hi,

> > On my page I use the following script to disable the right mouse click
> > The question : Is it possible that the user sees nothing when (s)he
> > rightclicks instead of an alertbox ?

> > <script language=JavaScript>
> > var message="Function Disabled"
> > function click(e)
> > {
> >  if (document.all)
> >  {
> >   if (event.button==2||event.button==3)
> >   {
> >    alert(message); // --> I want these alerts gone !
> >    return false;
> >   }
> >  }
> >  if (document.layers)
> >  {
> >   if (e.which == 3)
> >   {
> >    alert(message); // --> I want these alerts gone !
> >    return false;
> >   }
> >  }
> > }
> > if (document.layers)
> > {
> >  document.captureEvents(Event.MOUSEDOWN);
> > }
> > document.onmousedown=click;
> > </script>



Sun, 09 Mar 2003 03:00:00 GMT  
 Disable right click

Quote:

> Hi,

> On my page I use the following script to disable the right mouse click
> The question : Is it possible that the user sees nothing when (s)he
> rightclicks instead of an alertbox ?

Let me first point out that disabling the right mousebutton in absolutely no way will hide your
source code!

With that out of the way, let's go to work:

The utterly annoying alert box is only neccessary in IE 4.* on Windows
systems, as IE 5.0+ has the document.oncontextmenu event, specifically designed
for blocking the contextmenu, and Netscape 4.* allows you to quietly cancel the onmousedown event.

So let's build up a working copy of blocking the contextmenu and extend it's
functionality to handle these different cases.

<SCRIPT language=JavaScript>
<!--

if (document.all){ // We have IE 4+
    if (window.print){ // We have IE5+
        document.oncontextmenu = function(){
            if (event.srcElement.tagName=="BODY") return false;
        }
    } else { // We have IE4.*
        document.onmousedown = function(){
            if (event.srcElement.tagName=="BODY" && event.button!=1){
                if (navigator.platform.indexOf("Win")==0){ // We have Windows
                    alert('Sorry, the right mouse button has been blocked !');
                }
                return false;
            }
        }
    }

Quote:
}

if (document.layers){ // We have Netscape 4.*
    window.captureEvents(Event.MOUSEDOWN);
    window.onmousedown = function(e){
        if(e.target==document && e.which!=1) return false;
    }

Quote:
}

// -->
</SCRIPT>

Now we have a working copy of a script that blocks the contextmenu, and only
gives the user an alert box when completely neccessary. Furthermore, the user is still allowed to
right-click on images, links and so forth.

Some more lines added, and we would have a W3C DOM compliant
contextmenu-blocking script (using addEventListener() ).

Remember to check the FAQ or do a search on Deja before posting questions, this is a rather common
question!

--
Thor Larholm



Sun, 09 Mar 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Disable Right Click--> IE4

2. Disable right click

3. Disable right click

4. how to disable right-click contextMenu - but enable for form elements

5. How to disable right click event on an iframe??

6. disable mouse right-click

7. disable shortcut in right click

8. Disabling the right-click menu on a WebBrowser component

9. Cancelling a Right Mouse Button Click

10. Right click dialog

11. right and double click events on images

12. Right Click - Add to default menu

 

 
Powered by phpBB® Forum Software