?
Solved

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

Posted on 2011-02-21
25
Medium Priority
?
241 Views
Last Modified: 2012-05-11
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
Comment
Question by:feesu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 10
  • 3
  • +1
25 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 668 total points
ID: 34942236
0
 

Author Comment

by:feesu
ID: 34942270
It doesn't work with Chrome!
0
 
LVL 11

Assisted Solution

by:govindarajan78
govindarajan78 earned 668 total points
ID: 34942286
0
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 
LVL 82

Expert Comment

by:leakim971
ID: 34942302
>It doesn't work with Chrome!

With the test page provided ? Because it work for me...
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 664 total points
ID: 34942304
add this to body tag

<body oncontextmenu="return false;">
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 34942310
0
 

Author Comment

by:feesu
ID: 34942333
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
 
LVL 82

Expert Comment

by:leakim971
ID: 34942338
>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
 

Author Comment

by:feesu
ID: 34942341

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
 

Author Comment

by:feesu
ID: 34942346
leakim971,

To me it doesn't work, it works for everything except Chrome!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34942351
my version : 9.0.597.98
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 34942352
the try on html tag

<html oncontextmenu="return false;">
0
 

Author Comment

by:feesu
ID: 34942361
pratima_mcs,
On html tag solved my problem, do you think that there is a workaround that users can use?
0
 

Author Comment

by:feesu
ID: 34942367
leakim971,
How do I check my Chrome version?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34942369
tools menu -> About Chrome
0
 

Author Comment

by:feesu
ID: 34942373
9.0.597.98
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34942378
very strange... I tested it again, no context menu...
0
 

Author Comment

by:feesu
ID: 34942387
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
 
LVL 82

Expert Comment

by:leakim971
ID: 34942400
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
 

Author Comment

by:feesu
ID: 34942427
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
 
LVL 82

Expert Comment

by:leakim971
ID: 34942445
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
 

Author Comment

by:feesu
ID: 34942456
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
 
LVL 82

Expert Comment

by:leakim971
ID: 34942476
>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
 

Author Comment

by:feesu
ID: 34942543
Ok but at least only minimum number of users will be able to do that! Majority won't!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34942557
yes that is !
0

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question