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
Solved

Disable right click

Posted on 2006-07-11
8
345 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Numbers in JQuery file 11 66
xjs: how to get sum of value in for loop 2 18
ASP.NET Content Page 3 27
Copying table data to one another 15 29
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

840 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