Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disable right click

Posted on 2006-07-11
8
Medium Priority
?
360 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
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!

 

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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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 discusses how to create an extensible mechanism for linked drop downs.
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…

688 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