Solved

Disable right click

Posted on 2006-07-11
8
343 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
ID: 17083773
internet explorer and firefoxe if this is possible please

0
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 17084203
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
ID: 17084274
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:avo42
ID: 17084674
hi thanks

 how can i reomve the option so the user dont have the option to turn right click on or off
0
 
LVL 28

Accepted Solution

by:
Pravin Asar earned 500 total points
ID: 17084937
>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
ID: 17085030
Thank you for your help
0
 

Expert Comment

by:Ameerh24
ID: 23268605
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
ID: 23269480
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

776 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