Friday, May 1, 2009

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




Please visit my new Web Site https://coderstechzone.com



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>


Script tested for the following browsers:
Internet Explorer
Mozilla Firefox
Google Chrome

7 comments:

Anonymous said...

Could you please say to me if you know is here exists - monitoring of right - click, save web. page and print screen actions of logged in customers on theirs PC in so way that I can have record of it my ASP.Net application and upon undesirable actions of customers (save, copy, disable Programmatic clipboard access...)

in purpose to immediately log them out from access to web site?


Also I need to fit into my Web site video which would record (by permission of customers) that outside of their PC is no attempts to capture picture from the screen ...

If you able to say where to look for solution please let me know ...
I am waiting to here from you as soon as possible.

my e-mail:karina.northen@talktalk.net

Saion Roy said...

Hi Karina,
Basically its a universal problem & no one can secure their contents. No one can ensure you 100% protection. But you can tougher their job by the above ways that i have already described. For tracking issues i can suggest you one thing use dopostback method from your javascript to store the user information.

You can baught a solution from web but i am not sure about their performence. I think it will be better if you follow the above way to protect them + use dopostback to track them & for images use watermark.

Anonymous said...

Dear Shawpnendu,
Thank you very much for replay!!!:))))
I am VB programmer but I am not very familiar to javascript...:(

Maybe you can give exsmple for dopostback method from javascript to stote the user information and upon postback to redirect detected user to other page?

I read that can disable javascript..( so will disabbled protection given with javascript code...:(

I like idea to disable printing. But if in the same time protective javascript disabled from user who is trying to save and copy ... than it's again neitralisation of propection.

Is here possible to detect from ASP.NET Web application key stokes from keyboard or mouse click without using of javascript ????

Sincerely yours Karina Northen.
karina.northen@talktalk.net

Saion Roy said...

If you google you will get a lot of examples on _dopostback. If you think its a bit complex then you can try with javascript click() method.

For key press event.. Yes you can handle it & can raise postback.

Let me know if you need details.

Salvador Raich said...

Dear Shawpnendu:
I see you are an expert and can help me.
I have some HTML files, all text, in diskettes or CD format, and I intend to protect them against non authorised copies.
As long as I know, it means to hide html source, disable left and right mouse click, page printing, text selection/copying, hide temporary files, disable "See-code fountain", etc., and probably are necessary encrypted files and password protection.
What can you reccommend me for this?
Hoping to hear from you soon, I remain
Sincerely yours
Salvador Raich

Azis lamayuda said...

hello Shawpnendu ... Greetings. My name is Azis Lamayuda

I enjoyed reading your blog articles. I come from Indonesia. visit my blog: http://www.z33s.co.cc

friendship is everything ... thank you

Anonymous said...

i am passing parameter in onclick function, its fine in all browsers except firfox, kindly send me code which can work on firfox, below code not working
input type="text" id="a"
onClick="demo(a.value)"

Want to say something?
I WOULD BE DELIGHTED TO HEAR FROM YOU

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash