Thursday, November 3, 2011

Disable right mouse click,image toolbar,text,print on a page

Most of the site owners want to protect contents or images from abuses. For such type of feelings i think the top of the mind is to disable mouse right button. So that reader cannot open the action menu & can not copy the image or text. Let you have a professional photographer so that you dont want to loose your ownership cause its your creative work. Mostly you can share with others but not give it away. By disabling right mouse button does not give you the full comfort to protect your valuable contents since a lot of other technique visitor can apply to get your content. Such as screen capture, 3rd party URL capture tool, View source etc...

Here i tried to focus on bellow matters:
*** Disable mouse right click
*** Protect copy image
*** Protect copy TEXT
*** Protect page printing

One thing i want to share with you that no one can provide you the 100% perfection but you can do abuses job more harder. To disbale mouse right button use the below javascript client side code within the HEAD tag of your html or aspx page.
<script type="text/javascript">
function IE()
{
if (event.button==2)
return false;
}
function Others(e)
{
if (document.layersdocument.getElementById&&!document.all)
if (e.which==2e.which==3)
return false;
}
if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=Others;
}
else if (document.all&&!document.getElementById)
document.onmousedown=IE;
document.oncontextmenu=new Function("return false");

//if you found that some browser didn't support this script
//then you can redirect them into your custom page where you
//can tell your readers to open the page by IE/FF

if(navigator.userAgent.match(/Opera/ig))
location.replace("BrowserSugession.html");

if(navigator.userAgent.match(/Safari/ig))
location.replace("BrowserSugession.html");
</script>


The above script also can detect 3 button mouse right click event.

Disable image toolbar/protect to copy an image/picture:
The easiest way to protect your images is to disable image toolbar.

You can turn the image toolbar off for the whole page with this code inserted in between your <head> and </head> tags:

<meta http-equiv="imagetoolbar" content="no">

OR
<meta http-equiv="imagetoolbar" content="false">

Protect to copy an individual image by the following code:

<img src="netmixer.jpg" galleryimg="no">
OR
<img src="netmixer.jpg" galleryimg="false">


I have already said that there were no 100% effective formula to protect your image. But you can make this harder. If you are not satisfied yet then my suggession is to use watermark for your valuable images.

Disable TEXT selection:
Using the below javascript client side method you can protect most of the times your text content. The easy solution is to prevent readers from selecting/highlighting TEXT contents. So that abuses can not copy text from your html or aspx page. Insert the code between your <head> and </head> tags:

<script type="text/javascript">
function disableselect(e)
{
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar)
{
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>


So that abuses can not copy the page TEXT content as well as disallow user selection .

Disable page print:
This script can be used to disable printing of your website pages. This is useful to protect the contents of your site. For IE you can use below script:

<body onBeforePrint="document.body.style.display='none'"; onAfterPrint="document.body.style.display='';">

For a individual DIV:
<div id="protected" onBeforePrint="this.style.visibility='hidden'" onAfterPrint="this.style.visibility='visible'">your protected content</div>

Cross-browser solution to prevent document printing with CSS:<style type="text/css" media="print">
BODY {display:none;visibility:hidden;}
</style>

No comments:

Post a Comment