Solved

Disable right click

Posted on 2006-07-11
8
341 Views
Last Modified: 2008-12-31
HI all

I have a few images on my website

but when a view right clicks them i would like them to say a message
or right click totaly disabled on the web site

can you please also tell me where i have to place the code on my page as i dont know javascript at all

All help appriciated
0
Comment
Question by:avo42
8 Comments
 

Author Comment

by:avo42
Comment Utility
internet explorer and firefoxe if this is possible please

0
 
LVL 28

Expert Comment

by:Pravin Asar
Comment Utility
Here is a example which blocks R M B click for entire web page.

You want only for images ? to copy protect images. let me know.


<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<script language="javascript">
var fnPtr = null;
function Block () {
fnPtr = document.oncontextmenu;
document.oncontextmenu = function () { alert('OOPS'); return false;};
}
function UnBlock () {
document.oncontextmenu = fnPtr;
}
</script>
This lets you block and unblock the contextmenu (enable by Right Mouse Button (RMB) click.
<br>

<form>
      <input type="button" onClick="Block();" value="Block R M B" title="Click to Block R M B menu for img1">
      <input type="button" onClick="UnBlock();" value="UnBlock R M B" title="Click to Un Block R M B menu for img1">
</form>
</body>
</html>
0
 
LVL 12

Expert Comment

by:UnexplainedWays
Comment Utility
0
 

Author Comment

by:avo42
Comment Utility
hi thanks

 how can i reomve the option so the user dont have the option to turn right click on or off
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 28

Accepted Solution

by:
Pravin Asar earned 500 total points
Comment Utility
>how can i reomve the option so the user dont have the option to turn right click on or off

I am assuming you do not want user to give any control, hence a following code.
This one protects images from copying ( on image toolbar for IE and RMB menu)

<html>
<head>
<!--- Required for IE -->
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">
<title>Fade Slide Show Document</title>
</head>
<title>Untitled Document</title>
</head>
<!-- Set the R M B BLOCK ON IMAGE -->
<body onLoad="Block();">

<script language="javascript">
function Block () {
document.getElementById('img1').oncontextmenu = function () { return false; };
//document.oncontextmenu = function () { return false;};
}
</script>
This one does copy protect the image only.
<br>
<img id="img1" src="../images/0.gif" width="100">
</body>
</html>
0
 

Author Comment

by:avo42
Comment Utility
Thank you for your help
0
 

Expert Comment

by:Ameerh24
Comment Utility
I put this:
<a href="..." style="background: url(img.png); width: 500px; height:500px;"></a>
but it is not working
niether span nor div (when I put this same style for div it gives me save image as)

please can you try your solutions before u post it ??
0
 
LVL 28

Expert Comment

by:Pravin Asar
Comment Utility
I do not understand your comment. Please explain

For background image you may need to specify the style attribute as follows:

<a href="..." style="background-image: url(yourimage.gif); width: 500px;height: 500px;">&nbsp;&nbsp;</a>
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now