Solved

Disable right click

Posted on 2006-07-11
8
349 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
[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
8 Comments
 

Author Comment

by:avo42
ID: 17083773
internet explorer and firefoxe if this is possible please

0
 
LVL 29

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
Independent Software Vendors: 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!

 

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 29

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 29

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AngularJS: ng-repeat 25 54
PDF Turn Look 7 34
Javascript question 8 44
Run or cancel ColdFusion code from running with a button press 2 4
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

734 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