Disable right click for images (no alert)

Status
Not open for further replies.

tdsii

Banned
Banned
423
2008
2
0
I spent hours and hours and no good script is found.

I am seeking the following:
- disable rightclick for images only
- works on major browsers including chrome
- no alert message what so ever

All scripts online have alert messages! and if not it don't work.


I don't want smart asses to start telling me this is useless since people can disable javascripts.
 
17 comments
Stole this from IMDB:

Code:
 <img src="" onmousedown="return false;" onmousemove="return false;" oncontextmenu="return false;" />
It'll work as long as javascript has access to disable or replace context menus. It does not create any alerts in Firefox, have not tested any other browsers.

//EDIT

See it in action:
Code:
http://www.imdb.com/media/rm2885532672/rg2675546624
The image is between the <div class="primary"> tags.
 
Its quite easy using jQuery:
Code:
$('img').bind('contextmenu', function(e){
    return false;
});

But if your site doesn't use jQuery, I think it will be overkill to include the whole library just to use this function.
Are you using any CMS for the site? If so, I think you can just use xdb suggestion by adding it to where the CMS generating/outputting the images.
 
Same Problem

Hey i have the same problem as tdsii, im after a script to disable right clicking ONLY on images WITHOUT the alert and for the script to effect ALL images.

There is this code i found which disables right clicking ALL images but it has the alert on it aswell? is there some way to edit this code to take the alert off maybe?

http://www.dynamicdrive.com/dynamicindex9/noright2.htm


Thanx anyway
 
document.oncontextmenu=new Function("return false")

that line is used to remove the alert from "everything" disabled, puzzling stuff lol.

yer hopefully someone cracks it.
 
I see no point in this since new browsers can actually pull the image link into a simple menu like firefoxs page info...

Or if a user knows how to read the page source... Even google will cache your image...

Best thing to do is disable hotlinking as just viewing the image is like downloading it.
 
Loonycgb2 read my first post

I don't want smart asses to start telling me this is useless since people can disable javascripts.

edit: why people try to protect their software against crackers. groups will rip it anyway. I don't want people's ass to talk. think before you talk. most people don't know how to disable javascript. my audience are not nerds and people without a gf or life.
 
I don't want smart asses to start telling me this is useless since people can disable javascripts.

Spot on m8, i dont care if people can get the images any other way, its harder for them and time wasting if they want to get the images that way
 
Last edited:
Im free to say as i please.. And something to know people protect there apps because its WAY harder to crack an app then to download a image...

These kinds of codes are for people who think "oh wait maybe if i do this ill look a little smarter by trying to block them"

When as you could easily show images through a simple php file that watermarks all images being used with the named php file...

So again being a smartass? no im just letting you know theres more creative ways of doing things then this noob ass way that doesnt work..
 
All i want to do is stop people right clicking on my images, and i cant use a FULL disable right click option because there are songs on my php for people to right click and save as.

A nice quick way to do tht will be great thanx
 
Remove

PHP:
var clickmessage="Right click disabled on images!"

and all instances of

PHP:
alert(clickmessage);

From the above mentioned script, And that should do the job :)
 
Try this one out then:

PHP:
<script language=JavaScript> 
<!--  //Disable right mouse click Script //By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive 
//For full source code, visit http://www.dynamicdrive.com  

var message="";  
/////////////////////////////////// 

function clickIE4(){
if (event.button==2){ return false; } 
}  

function clickNS4(e){ 
    if (document.layers||document.getElementById&&!document.all){ 
        if (e.which==2||e.which==3){ 
            return false; 
         } 
    } 
}  

if (document.layers){ 
    document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4; 
} else if (document.all&&!document.getElementById){
    document.onmousedown=clickIE4; 
}  

document.oncontextmenu=new Function("return false")  // -->  
</script>



Just paste this above </body>. Works on FF and Opera, tested by me =)

Edit: Just realized that this is for everything, And not just images O.o
 
Yer that does work but for everything m8, i cudnt right click my links thats all.

Got to be a way around this...

thanx alot for trying :)
 
I have found a way!!! :D

This way works with images INDIVIDUALLY, which is actually better. And its only 1 line of code......


Take your image tag:

Code:
<img src="mypic.jpg" height="24" width="100">


Add the following event handler to the end of your tag:

Code:
onContextMenu="return false;">


So it will look like this:

Code:
<img src="mypic.jpg" height="24" width="100" onContextMenu="return false;">

DONE! :)


You can also add an alert message before the return false like this:

Code:
<img src="mypic.jpg" height="24" width="100" onContextMenu="alert('YOUR MESSAGE HERE');return false;">


I would have prefered a code to control every image at once, but this way i have more control individually, its great!! enjoy :D
 
Last edited:
Status
Not open for further replies.
Back
Top