[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

JavaScript - Disable rightclick code doesn't work with all browsers!

Hi,

The below worked out for me in IE only, how do I manage it with other browsers?


<script language="javascript">


    var message="Sorry, Right Click is disabled.";
   
    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
feesu
Asked:
feesu
  • 11
  • 10
  • 3
  • +1
3 Solutions
 
leakim971PluritechnicianCommented:
0
 
feesuAuthor Commented:
It doesn't work with Chrome!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
leakim971PluritechnicianCommented:
>It doesn't work with Chrome!

With the test page provided ? Because it work for me...
0
 
Pratima PharandeCommented:
add this to body tag

<body oncontextmenu="return false;">
0
 
Pratima PharandeCommented:
0
 
feesuAuthor Commented:
leakim971,
What test page? I copied the code, and it works fine in IE and Firefox.

pratima_mcs,
Adding that in the body has another problem, if you right click at the very bottom of the page it works, and you can get a context menu, maybe cuz it is restricted to only body and not the whole page! Add some content, and try, it will disable the right click on the content, but if you right click at the bottom in the white space, it accepts! In all browsers!
0
 
leakim971PluritechnicianCommented:
>What test page? I copied the code, and it works fine in IE and Firefox.

OK, the code in the link. I tested it on my Chrome browser, do a right click and the context did not appear.
0
 
feesuAuthor Commented:

govindarajan78,

Below is the first comment posted on your article:

I don’t know if this works for Firefox, but it does NOT work on Google Chrome… the Function Disabled alert does come up but users can still see and use the right click menu to save images from the website : (
0
 
feesuAuthor Commented:
leakim971,

To me it doesn't work, it works for everything except Chrome!
0
 
leakim971PluritechnicianCommented:
my version : 9.0.597.98
0
 
Pratima PharandeCommented:
the try on html tag

<html oncontextmenu="return false;">
0
 
feesuAuthor Commented:
pratima_mcs,
On html tag solved my problem, do you think that there is a workaround that users can use?
0
 
feesuAuthor Commented:
leakim971,
How do I check my Chrome version?
0
 
leakim971PluritechnicianCommented:
tools menu -> About Chrome
0
 
feesuAuthor Commented:
9.0.597.98
0
 
leakim971PluritechnicianCommented:
very strange... I tested it again, no context menu...
0
 
feesuAuthor Commented:
I am surprised, but <html oncontextmenu="return false;"> worked fine for me, and across all browsers.

Do you think that this has a bug or a gap? Why not so many people using it?
0
 
leakim971PluritechnicianCommented:
Test it with Opera
I don't know what you're trying to protect but if it is source or image link, people will always able to choose view source (via the browser menu) to get what they want.
0
 
feesuAuthor Commented:
I care for IE,Chrome, and FF mostly.

I can open it it with popup that does not have a tool bar or a menu. Just like banks websites do, or do you have another idea?
0
 
leakim971PluritechnicianCommented:
I'm ok if you're agree that you only reduced the number of people able to get the content of your page only. Else, we can reload your page with a menu and so on...
0
 
feesuAuthor Commented:
I give up, how do banks and online examination sites work?

I wish to have a page that does not allow users to print/copy any content!
0
 
leakim971PluritechnicianCommented:
>I give up, how do banks and online examination sites work?

applet, flash ? which sites ? you will always able to get content of a page. It only depend the knowledge of the user.

if you click on the print button, you're able to do screen copy for example but ok it's only a picture
0
 
feesuAuthor Commented:
Ok but at least only minimum number of users will be able to do that! Majority won't!
0
 
leakim971PluritechnicianCommented:
yes that is !
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 11
  • 10
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now