• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 601
  • Last Modified:

Suppress Right Click in Firefox

We want to disallow a right click (to download pictures) from our web site.

We are using this JavaScript code which works fine in IE:
function noRightClick() {
      if (event.button==2) {
            alert('Sorry,  You can not right click.');
      }
}      
and then
document.onmousedown=noRightClick

This does not work in FireFox. What can I do to make it function similarly in FireFox?
0
Richard Korts
Asked:
Richard Korts
1 Solution
 
bluV11tCommented:
Hi!
This code works in both browsers:
http://www.billybear4kids.com/clipart/riteclic.htm
<script language="JavaScript"> <!--
// No rightclick script v.2.5
// (c) 1998 barts1000
// barts1000@aol.com
// Don't delete this header!
 
var message="Sorry,  You can not right click."; // Message for the alert box
 
// Don't edit below!
 
function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
// --> </script>

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
This also works perfect, I got it from somewhere earlier,

<script language="javascript">
 
               var message="Right click is not allowed.";
               function clickIE4(){
 
                             if (event.button==2){
                             alert(message);
                             return false;
                             }
               }
 
               function clickNS4(e){
                             if (document.layers||document.getElementById&&!document.all){
                                            if (e.which==2||e.which==3){
                                                      alert(message);
                                                      return false;
                                            }
                                    }
               }
 
               if (document.layers){
                             document.captureEvents(Event.MOUSEDOWN);
                             document.onmousedown=clickNS4;
               }
 
               else if (document.all&&!document.getElementById){
                             document.onmousedown=clickIE4;
               }
 
               document.oncontextmenu=new Function("alert(message);return false;")
 
</script>

Open in new window

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Richard KortsAuthor Commented:
To bluV11t:

Does not work in FireFox. Same as before. I did not try in IE.

However, I may not be using it right.

I put it in it's own <script></script> tag set, I have a lot of other JavaScript already in there, I left that alone but REMOVED the previous document.onmousedown
0
 
bluV11tCommented:
Did you specify language in the script tag? Tested it in both browsers...

In FF Ctrl+Shift+J to check any javascript errors. If error console is full of errors, click clear button and reload page.
0
 
Richard KortsAuthor Commented:
To bluV11t:

I combined all the Javacript into one. It works in IE 7.0. It DOES NOT work in FireFox 5.0.

Attached is the (generated) HTML with the javascript
proofs-ol1a.txt
0
 
Richard KortsAuthor Commented:
To logudotcom:

Your solution DOES NOT work in Firefox either. I have not yet tried it in IE.
0
 
Richard KortsAuthor Commented:
To logudotcom:

Sorry, I had a JavaScript error. Yours works. You get the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now