/    Sign up×
Community /Pin to ProfileBookmark

disable right mouse button on <img src="">

Hello,

I would like to disable right mouse button,
but not on the entire page, but just on
the image file <img src=””> to make an easy way
for users not to write the image file on disk.

How is that possible?

Thanks in advance.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoNov 29.2005 — Once your page loads on a user's comp via their web browser all of your images are temporarily saved to their computer. Also, all the user has to do to get around no right clicking is to print page and then just go into photoshop or paint and just cut out the part that they want. basically this means that no right clicking is pointless.
Copy linkTweet thisAlerts:
@nylonauthorNov 29.2005 — Believe me - I know that ?

That is not the point.

How to disable the right mouse menu when

someone clicks on a single <img src="">

When someone clicks at specified IMG with right mouse button

there should be no actions taken (no pop-up menu)

That is the point of my question ?
Copy linkTweet thisAlerts:
@konithomimoNov 29.2005 — <i>
</i>&lt;script type="text/javascript"&gt;
var overImage=0;

function mouseDown(e) {
var clickType=1;
var tgt="";
if (parseInt(navigator.appVersion)&gt;3) {
if (navigator.appName=="Netscape") {
clickType=e.which;
tgt=""+e.target;
if (tgt.length!=0 &amp;&amp; tgt.charAt(tgt.length-1)=="#")
overImage=1;
}
else {
clickType=event.button;
if (""+event.srcElement.className=="disabledMenu")
overImage=1;
}
if (clickType!=1 &amp;&amp; overImage) {
alert ('Right-click menu is disabled for this image.')
return false;
}
}
return true;
}
if (parseInt(navigator.appVersion)&gt;3) {
document.onmousedown = mouseDown;
if (navigator.appName=="Netscape")
document.captureEvents(Event.MOUSEDOWN);
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@felgallNov 29.2005 — Decent web browsers don't allow the context menu to be disabled at all. Each Windows keyboard also comes with a key on the keyboard (immediately to the left of the right CTRL key) to bring up that menu even if the mouse button is disabled. The key on the keyboard is only disabled in older web browsers using oncontextmenu (while decent web browsers ignore all such attempts to interfere with their standard functions).

A transparent image in front of the one you want to protect will stop the context menu being able to be used to save the image while not interfering with the normal use of that menu. This works on all browsers but of course doesn't stop the images from being taken in any of dozens of other ways - see http://javascript.about.com/library/blimgprot.htm
×

Success!

Help @nylon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...