Disable right click on images?
|
pengi2
Joined: 2006-10-07
Posts: 19 |
Posted: Thu, 2006-10-12 02:58
|
|
I know disabling right click on images is a weak protection measure but anyways I have a request to implement it in gallery 2 integrated with drupal. I've searched the forums here and there were few discussions on the topic, and those that I did find were for gallery 1, lacked details as to where to put the script etc. Can anyone lay it out for me? Thanks |
|
| Login or register to post comments |

Posts: 14
Hey Hi Pengi,
I've managed to disable right click for G2 which I'm running standalone using Mincel's Carbon theme. I don't know if you're using a theme pack or not, but I added javascript to the gallery2/themes/yourthemehere/templates/theme.tpl file and I did it in the following way:
First, in the theme.tpl file it asks you to make a duplicate of the file and add customizations to that, so I created the directory templates/local and copied theme.tpl to there.
Then, I created a javascript file rightclick.js which contains the following code gleaned freely from cgiscript.net: (The <scipt> tags are commented out for use in the rightclick.js file. If you're putting the javascript in the <head> section of the html, then uncomment those tags)
//<SCRIPT LANGUAGE="Javascript"><!--
// ***********************************************
// AUTHOR: WWW.CGISCRIPT.NET, LLC
// URL: http://www.cgiscript.net
// Use the script, just leave this message intact.
// Download your FREE CGI/Perl Scripts today!
// ( http://www.cgiscript.net/scripts.htm )
// ***********************************************
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
var EnableRightClick = 0;
if(isNS)
document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
if(EnableRightClick==1){ return true; }
else {return false; }
}
function mousehandler(e){
if(EnableRightClick==1){ return true; }
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
function keyhandler(e) {
var myevent = (isNS) ? e : window.event;
if (myevent.keyCode==96)
EnableRightClick = 1;
return;
}
document.oncontextmenu = mischandler;
document.onkeypress = keyhandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
////-->
//</script>
I placed rightclick.js in the gallery2/themes/yourtheme directory and chmod'd it to 644.
Then, in local/theme.tpl, I added the tag: <script type="text/javascript" src="{g->url href='themes/carbon/rightclick.js'}"></script> in the (* Include this theme's style sheet *) section so that it looks like this:
{* Include this theme's style sheet *}
<link rel="stylesheet" type="text/css" href="{g->theme url="theme.css"}"/>
<script type="text/javascript" src="{g->url href='themes/carbon/theme.js'}"></script>
<script type="text/javascript" src="{g->url href='themes/carbon/rightclick.js'}"></script>
As I said, I'm using the carbon theme so your path would look like: themes/yourthemehere/rightclick.js
Voila! No more right clicking!
Hope this helps,
- Jim de Geus