Saturday, April 12, 2008

Disable Right-Click for Your Website

NO RIGHT-CLICK for Images
Have you ever tried so hard on your website to stop someone stolen your graphics as their own.

Here is an extra step in protecting your graphics/images from being saved. But there is no foolproof method to stop someone from copy your images. If they really want something from your web site, they can find ways around it. But at least you can eliminate some proportion of visitors stealing images from your web site.

It is very simple. Whenever someone right clicks his/her mouse, a message will popped up to show him/her that he/she do not have permission to do so. Place the script below within the head tags of your html.

<script language="JavaScript">
<!--
var msg="Right-click is disabled!";

function rightclick(go) {
    if (document.all) {
        if (event.button == 2) {
            alert(msg);
            return false;
        }
    }
    if (document.layers) {
        if (go.which == 3) {
            alert(msg);
            return false;
        }
    }
}
if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=rightclick;
// -->
</script>


NO RIGHT-CLICK for Sources
To protect the whole page of your web site, copy and paste the script below within your head tags in your html.

<script language="JavaScript">
<!--
function rightclick(e) {
    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
        return false;
    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
        alert('Right-click is disabled!');
        return false;
    }
    return true;
}

document.onmousedown=rightclick;
document.onmouseup=rightclick;
if(document.layers) window.captureEvents(Event.MOUSEDOWN);
if(document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=rightclick;
window.onmouseup=rightclick;
//-->
</script>

0 comments:

 

Get paid for your opinions! Click on the banner above to join Planet Pulse. Its totally free to sign up, and you can earn UNLIMITED. Find out more by visiting PLANET PULSE.
July Code Blog Copyright © 2010 Blogger Template Designed by Bie Blogger Template