How to disable copy, paste, cut and mouse right click using Javascript and CSS

Somebody asked me yesterday what have to be done in order to disable copy/paste function and to stop the visitors (or, at least, most of them) to copy the content of her articles. Well, I prepared the answer, but you can learn from it as well... So I am posting it here, hoping it will help.

Apply this code in your html document inside the <body> tag in order to disable drag and select (and copy/paste using the Ctrl+C/Ctrl+V keys).

ondragstart=’return false’ onselectstart=’return false’

Practically, the tag should look like this (considering there is no onLoad or other stuff like that already added):

<body ondragstart=’return false’ onselectstart=’return false’>

Apply this script in your html document before closing after the starting and before the closing the <head> tag:

<script type="text/javascript">var message=FunctionDisabled!;function clickIE4()
{     if(event.button==2) { alert(message);returnfalse;}}function clickNS4(e)
{if(document.layers||document.getElementById&&!document.all)
          {if(e.which==2 || e.which==3) { alert(message);returnfalse;}}}if(document.layers)
{ 
     document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4;}elseif(document.all&&!document.getElementById)
    { document.onmousedown=clickIE4;} 
document.oncontextmenu=newFunction(alert(message);returnfalse)</script>

Add some necessary security CSS elements to the <body> tag.

For example, add in the CSS file

body {
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -o-user-select: none;
}

In case you want to place them as CSS style in the html document, the <body> tag will look like this:

<body ondragstart=’return false’ onselectstart=’return false’ style=’user-select: none; -moz-user-select: none; -webkit-user-select: none; -o-user-select: none;>

This is basic protection only! That will help you in most of the cases, but advanced users will bypass it with ease by disabling JavaScript on their browser or using firebug to see the html source.

Related Articles

seo search engine optimisation The search engine optimisation part is very important for websites - they have to match certain criteria in order to appear as often as possible in the search results on Google and Bing. SEO (search engine optimization) starts from site / online store / platform development because it involves a specific structure of the pages, it involves an ease to browse for the visitors (for your clients) and it involves quicky loading when accessed. Our sites are delived already optimized, but if you have already a solution developed by someone else we analize your website and we offer consultancy - we'll tell you about the options you have about to boost its visibility and organic traffic.

realizăm site-uriWe develop websites to present your activity to the world and applications for internet that help you organize your activity as eficient as possible and without loses (in money, time and energy) wherever you are. Do you need an online store or a tool available for you anytime? We can develop that as long you reserve a domain name and some hosting space, the app is our job.

As an extension to your site or web app we can provide an app for your smartpone / table to keep you always informed about what's happening with the product already developed.

developing appsWe develop web applications and mobile apps (Android) for various companies and organisations according to their specifications and requirements. The apps are being used by employees and partners to work more efficient and with less costs for the company: the web applications can be accessed through the browsers installed on smartphones and tablets but the usage of a complementary mobile app can make efficiency to go up (it can increase the communication between people or it can show things not so important on PC).

We offer support for the applications used now and we develop them further using modern technologies.

Consulting bussiness online / itWe offer consultancy about the informatic system you have installed and we offer sollutions to make the more efficient, to improve and develop them further, we analize the activities inside your company and / organisation and we offer sollutions for the projects you want to develop.

If you don't have a website, an online store, a web application or a mobile app (Android) but you want to develop one for yourself or your company we offer the initial consultancy, the one that's necessary before starting anything about such project.

Share this URL on social social

"Cu capãtul arcurilor, trecînd,
rãzboinicii
mîngîie roua..."

Yosa Buson (1715-1783)

facebook sharing button
twitter sharing button
messenger sharing button
reddit sharing button
wordpress sharing button
whatsapp sharing button
tumblr sharing button
pinterest sharing button
blogger sharing button