/    Sign up×
Community /Pin to ProfileBookmark

Disable right mouse click ONLY on images | have the script but…

Hi all,

i have found the script of [B]disable right click only for images [/B] but this one gave annoying alerts, but i need something with no alerts.

I cant fix it with my java knowledge, i need your help. ?

The script is from [URL=http://www.dynamicdrive.com/dynamicindex9/noright2.htm]here[/URL],

[CODE]<script language=”JavaScript1.2″>

/*
Disable right click script II (on images)- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.comf
*/

var clickmessage=”Right click disabled on images!”

function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName==”IMG”){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById){
if (e.which==3&&e.target.tagName==”IMG”){
alert(clickmessage)
return false
}
}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

if (document.all)
document.onmousedown=disableclick
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()
</script>[/CODE]

to post a comment
JavaScript

20 Comments(s)

Copy linkTweet thisAlerts:
@scragarApr 20.2005 — just remove all the instances of "alert(clickmessage)", problem solved.

although I should warn you that that does atsaluptly no good.
Copy linkTweet thisAlerts:
@exosferauthorApr 20.2005 — i did that, but...

after removing "alert(clickmessage)"; lines the script became useless, i can right click on pictures ?
Copy linkTweet thisAlerts:
@jbotApr 20.2005 — i did that, but...

after removing "alert(clickmessage)"; lines the script became useless, i can right click on pictures ?[/QUOTE]


good, that's the way it should be. disablement scripts are plain wrong. what gives you the right to break my browser. nothing. so, do yourself a favour and forget about it. my browser belongs to me, not you.

if you're worried about people downloading your images, then don't upload them in the first place. as soon as i visit your site, any images are automatically downloaded and saved onto my machine. hence the futility of trying to obviate that.
Copy linkTweet thisAlerts:
@scragarApr 20.2005 — OK, but I was still right about your script being useless.

[code=php]<script type="text/javascript">

function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
event.button=1;
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
e.which = 1
return false;
}
}
else if (document.getElementById){
if (e.which==3&&e.target.tagName=="IMG"){
e.which=1;
return false
}
}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

if (document.all)
document.onmousedown=disableclick
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()
</script>
[/code]
Copy linkTweet thisAlerts:
@exosferauthorApr 20.2005 — scragar,

thanks for the answers, but the right click still works.....

jbot,

I didnt asked if this script is fair to visitors or not, i've asked for technical help.

but since you answered that way, let me state my opinion.

What gives me the right to "break" your browser is that i am the owner of my site. the visitors can leave my site, if they dislike the way it works. (actually i am not breaking something anyway, it is only a part of my design)

By the way you can choose a browser that is "unbreakable", if this kind of small java scripts irritates you.

I know that the pictures are downloaded to visitors machine, even without this, a visitor can easily steal my images with PrintScreen button. But when something evil is unavoidable, why should i made it easier to abuse? i will do my best to stop image stealers, dissuasion is one of the ways.

I believe that -not all- but many people would be lazy to steal my pictures, they would steal from other websites that allow right click.

i wish i made myself clear about this issue...
Copy linkTweet thisAlerts:
@scragarApr 20.2005 — I give in trying any more, since I have no experience in this kind of thing, try playing about with your "return false" codes(change them to "return true") or something like that...


Oh and as for being unable to right-click all I will do is go "tools, options, interactivity, javascript, disble custom javascript menus" and all of a sudden I can get any image I want, not exactly dificult. -- I don't use IE, so you won't find those options in IE(they exist in firefox, but the menu's are different), I can't remember the english translation of my browser, but it's got a horrible looking japanesse name...
Copy linkTweet thisAlerts:
@jbotApr 20.2005 — What gives me the right to "break" your browser is that i am the owner of my site. the visitors can leave my site, if they dislike the way it works. [/QUOTE]

yes, the site belongs to you, but the browser belongs to the user. as such you don't have the right to disable their features. they exist for a reason and in doing what you are adversely affecting the usablity and accessibility of their machines. that is plain wrong. your argument that you can do the hell what you like is no different from spammers and malware merchants who think it is their right to fill up machines with dodgy software simply because it is their software.


actually i am not breaking something anyway, it is only a part of my design[/QUOTE]

the contextmenu of a browser is not part of your design though. it belongs to the user, not you.

anyway, you completely misunderstand the term "broken" here, don't you. it refers to the fact that the browser's inherent functionality has been broken, ie you broke the display of the contextmenu by rendering it unfunctional.


By the way you can choose a browser that is "unbreakable", if this kind of small java scripts irritates you.[/QUOTE]

what does that mean? part of the browser is being broken (disabled) by you on purpose. oh, and it's javascript, not java script. java != javascript.


I know that the pictures are downloaded to visitors machine, even without this, a visitor can easily steal my images with PrintScreen button. But when something evil is unavoidable, why should i made it easier to abuse? i will do my best to stop image stealers, dissuasion is one of the ways. [/QUOTE]

again, if you're so worried just don't upload them in the first place. it's not frikken rocket science.
Copy linkTweet thisAlerts:
@scragarApr 20.2005 — add watermarks(feint text with the name of your site on), this will reduce the atempts to steal them, of course someone could edit them and remove it, but that's unlikely.
Copy linkTweet thisAlerts:
@exosferauthorApr 20.2005 — yeah thats right scragar. I also dont use IE for browsing, however over %90 of my visitors use IE for browsing. This percentage is approximately same for other websites too.

Since there are other nice and better alternatives, people still uses IE. That is just like what I want to say above.

Yes it still easy to steal pictures with other methods, but right click is the easiest, just like %90 of people uses IE, %90 of people uses right click to save pictures, many of them doesnt know other ways, and won't use it.

I'm still looking for someone to help me with this code.


jbot,

I am not attacking or abusing someone (like spammers), i am protecting my site. This cant be argued.

Disabling right click on images doesnt effect browsing that much like you exaggerated. What is the possibility and the reason to right click on an image? Many visitors wont ever notify this prohibition anyway.

I did understood the word "broken", and with "unbreakable" browsers, i mean browsers like firefox, just scragar explained in his answer. (since english is not my native language, i am sorry for any misunderstandings)

"Contextmenu of a browser is not part of your design": This can be argued. There are alternatives of buttons in other menus of browsers. "Back" or "Refresh" buttons in contextmenu are also in top menus for example. Therefore it is not totally abuse of "affecting the usablity and accessibility" of visitors.(by the way i am only disable it while mouse is on a picture)

Since if you are one of the image stealers or not, lets not argue on this topic anymore because you look from visitors eye, and i think as a site owner, therefore our priorities are different while browsing a web page.

"if you're so worried just don't upload them in the first place": first of all you should understand this is impossible and childish.
Copy linkTweet thisAlerts:
@jbotApr 20.2005 — "if you're so worried just don't upload them in the first place": first of all you should understand this is impossible and childish.[/QUOTE]

it's not childish. it's how the web works. you publish something online, it's open to all. sourcecode, images, attachments, are all available to the surfer, casual or otherwise. if you don't want to be part of that, then don't upload. the web was not designed to hide its content.

i do understand where you're comig from, I just don't agree with your solution. disabling features of a browser is not right. period. and no matter how you dress it up as a site protection, you are still infringing on the end-users' ability to surf unimpeded.

childish? if there's any growing up to do it is those who think that just because they own a website they also own those who visit the site.
Copy linkTweet thisAlerts:
@jbotApr 20.2005 — what exactly are you trying to do, beyond image protection. what size are the images, for example?
Copy linkTweet thisAlerts:
@scragarApr 20.2005 — can you belive I have to add a message before I'm allowed to quote myself? that's just plain rude.add watermarks(feint text with the name of your site on), this will reduce the atempts to steal them, of course someone could edit them and remove it, but that's unlikely.[/QUOTE]
Copy linkTweet thisAlerts:
@exosferauthorApr 20.2005 — it's not childish. it's how the web works. you publish something online, it's open to all. sourcecode, images, attachments, are all available to the surfer, casual or otherwise. if you don't want to be part of that, then don't upload. the web was not designed to hide its content.

i do understand where you're comig from, I just don't agree with your solution. disabling features of a browser is not right. period. and no matter how you dress it up as a site protection, you are still infringing on the end-users' ability to surf unimpeded.

childish? if there's any growing up to do it is those who think that just because they own a website they also own those who visit the site.[/QUOTE]


I know these...

But you should understand that I just cant shut down my website because this is the way web works. Its just like I can't stop walking in streets and lock myself to my room because there are dangerous people outside.

Image or content stealing will always happen in web. This is unavoidable, just like the crimes in real life.

What we are doing is decreasing the possibility.

Since what transfered between my host and visitors computer are codes. The way that the code operated is under visitors control. Yes, the javascript code disables right click menu in IE, but not in Firefox. The user has the freedom to see my pages source code, I am not cloaking anything. These are of course right when the code does not include virus or anything like that.

Also there is no difference between right click or left click. If the visitor clicks ON MY SITE, I should control it. This is interactivity. Not end-users' ability. Just like when they left click on a link, they go to a page that I DECIDE, when they right click on my pictures, they would get message that it is copyrighted. period. No difference between right click or left click. It differs from browser to browser. Just because all of you are Microsoft Windows minded, you all think that right click will give you properties window. It is all about how do you look to the topic. People who use other OS' should understand me better.

Think about flash animations. What do you get when you right click on them? It is totally under control of the coder of animation.

[I]If there's any growing up to do it is those who think that just because[/I] [B]they visited a website they also own that web site and all images in it.[/B] :mad:
Copy linkTweet thisAlerts:
@felgallApr 22.2005 — Web browsers download everything belonging to a web page onto the local computer FIRST and display the page from there. Regardless of what "protection" you attempt to build into the page the person viewing the page already has a copy of all of your images on their computer and all they need to do is to move them to somewhere more permanent.

The only form of image protection that works is to embed a copyright notice into the image itself. If your copyright notice specifies your web site then if your images do get stolen then they will be advertising your site.
Copy linkTweet thisAlerts:
@balloonbuffoonApr 23.2005 — I'd just like to add-- if a website (tries to) disable my right click, I have less respect for the author and am likely to leave. (Even though I use Firefox and can still access the right click menu when someone has tried to disable it.) Most of the time people aren't trying to steal your images when they right click, therefore you shouldn't try to disable it. Anyway, your images probably aren't even worth stealing! ?

-Steve
Copy linkTweet thisAlerts:
@leannenFeb 02.2006 — I design banners in photoshop and have managed to disable the right-click "Save as" option. Why the hell shouldn't I?

I did this after finding some images that I had produced on another website. People are naive if they think this won't happen to them.

The Internet is free for anyone to do as they please. If that means disabling a common feature, then so be it. Im not wasting my time designing something for some loser to come and copy for their own benefit.

Hell... if we should all have the right to see everything on the net without limitations, I might aswell give you my online banking password right now!!

leannen.
Copy linkTweet thisAlerts:
@Tweak4Feb 02.2006 — I design banners in photoshop and have managed to disable the right-click "Save as" option. Why the hell shouldn't I?[/QUOTE]
Because its rude, invasive, encourages people to leave your site quickly, and discourages them from returning.

It's not a matter of people not thinking it will happen to them. It will, but this is not a solution thats going to stop it.

Right click on this page and look at the menu that comes up. There is a lot of stuff there that people may have very valid reasons to use. Copy, Add to Favorites, Properties, Print, Refresh, etc. People get in routines, and disabling the menu disrupts the routine for people that make use of the menu. So taking away the freedoms that your users are used to does nothing aside from drive them away from your web site.

The very nature of the internet is about freely sharing information. As a web designer, you should strive to make the information you are presenting as accessable as possible. Shutting off the features of your user's browsers, aside from being rude, alienates your users and will likely ultimately result in reduced traffic to your site, which severly limits the accessibility of your site.

If you are such a control freak that you want to have domain over every aspect of the user experience, then the internet is not the place for you.

I design and maintain websites for a living. I do many of my own graphics. Those I can't do are done by my sister and brother-in-law- both graphic designers. We all know that putting things on the web has an inherant risk of theft. However, we also accept that there is nothing that can be done. Even the most basic of users out there knows that there is a mysterious "cache" out there where they can go to retrieve images they couldn't save for one reason or another. Almost as many either know how to disable javascript, or surf with it off all the time, which renders your scripts completely useless (of course, we're not even considering the huge crowd that have mastered the art of pressing the Print Screen key).

The moral of the story is, suck it up and deal with it. Scripts that disable browser features are BAD. Don't use them. If you don't want images stolen, don't post them on the internet (or at the very least, watermark them).

Oh, and leannen... This may stop a casual user from saving the image on their own pc, but anyone who knows enough to steal an image from your site and repost it on their own is going to know how to:

a) grab the image url from your source

b) file>save as your entire web page

c) disable your right-click script

d) disable all javascript or

e) screen capture the image

There are so many different ways that are common knowledge now it's hardly worth the effort to try and block them. Many people even steal images purely out of spite to piss off the naieve people that think such a script "protects" anything...
Copy linkTweet thisAlerts:
@felgallFeb 02.2006 — My browser is set to ignore all attempts to disable right clicks in the first place so that I don't have to worry about such rubbish.
Copy linkTweet thisAlerts:
@CinderellaFeb 02.2006 — even if you don't disable the right click, if someone wants to steal an image there are other ways to do it.

They could view page source and get the image if it's accessible via a link.

Or they could highlight the picture+ Ctrl+C

The best way to keep your pictures safe it to 1: add your name, that way, you'll hopefully get lucky and an amature will try to steal it, and wont know how to get rid of the evidence of you.

2: Add your watermark

Or 3: don't post them at all.

Sorry guys, I was just rambling my thoughts...


___________
Are you all happy? I took a break from the coffee loung.

Now if you'll excuse me, I have a board with my name on it.
Copy linkTweet thisAlerts:
@wetlanderFeb 02.2006 — to steal an image that is protected with any sort of "anti-right clicking" script is oh so difficult. I mean i have to put energy into my left finger and keep the left mouse button held down till i drag the image icon all the way up into the address bar where my finger gives out and the drag-image is released. wala, i have just the image and no javascript protecting it.

the only way to protect your images, as has been said, is doing so through legal methods. copywriting, watermarking and such.
×

Success!

Help @exosfer 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...