开发者

Disabling Copy/Paste in a Web Page

How Do I disable the copy paste feature in my webpage. To be precise, I don't want my users to copy any information from my website and use them for personal purposes. The previous question on the same topic doesn't give enough explanation. The onselect and ondrag aren't w开发者_JAVA百科orking. Please help.


I don't want my users to copy any information from my website and use them for personal purposes

There is no way to do this. If someone really wants your information, they can get it.

You might be able to give them a litte bit of trouble with disabling certain functions using javascript or whatever...but you'll only give the people who don't know much about technology that trouble. And usually those people aren't even trying to copy your data. The one's who are, will figure out a way.


If you publish information online, you should clearly indicate your copyright claim on the page (or indicate the type of license you issue the content under). Please find and read the copyright law of your territory to understand what this does and doesn't allow - for example, in the UK there are provisions for making personal copies of copyrighted material and for using parts of copyrighted work for critical review or parody.

You can't stop people from copying the content on your page. You can make it more difficult for them to do - but this will have a negative impact on your page. Techniques such as preventing the left-click of the mouse, intercepting keyboard events or converting your entire article into images just make your website less usable.

If you have textual information on your website, I can re-type it even if you've stopped every other method of me copying the image. If you have an image and you've managed to lock out everything else, I can still do a screen-grab (not to mention the fact that my browser caches all the images in a temporary folder on my machine).

Your content-paranoia affects many people who set up a website - but the idea behind the Internet is that it is used for sharing information.


Just add the following code to the HEAD tag of your web page:

<script type="text/JavaScript">
//courtesy of BoogieJack.com
function killCopy(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=killCopy
document.onclick=reEnable
}
</script>


By default, Chrome and Firefox block disabling the right click menu. You have to manually edit an entry in about:config in Firefox to prevent it being blocked, which is not something you can force your visitors to do.

Regarding IE, you can modify your BODY tag like so:

<body onContextMenu="return false">

Which will prevent the right click context menu.

Other than that, the next best step is to create an image of your text, place it in a .swf (flash) document, and point the page to load the .swf as the page. This will cause all browsers to display the flash context menu on right click, and will prevent simple copy/paste efforts.

I do agree with previous replies, regardless of method used, any user can simply use their Print Screen key, paste the image in Paint (or other program), save it, and use OCR to grab your text.


You need to rethink your strategy if you're resorting to these measures on the front end. What you are trying to do is inherently wrong.

As a visitor to your web page, pulling something like this is just going to annoy me - I will eventually figure out what you've done and get around it. That said, I've recently found this particular method can be quite effective if you're aiming to restrict impatient or non-technical users. Proceed with caution...

<div class="text">
  <p>Hello, world! Sadly, <a href="#">I won't work</a>.</p>
  <img alt="I can't be dragged or saved either :(" src="tree.png"> 
  <div class="preventSelect"></div>
</div>

...and the CSS:

.text {
  position: relative;
  width: auto; /* can be fixed as well (ie 400px) */
  width: auto; /* can be fixed as well (ie 400px) */
  z-index: 0;
}

.preventSelect {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
}

The obvious drawback for this method is that the user cannot interact with anything inside the div we're preventSelecting. That includes links, buttons, images etc.

Please don't use this unless you absolutely have to. Frankly, it's a pain in the ass for everyone.


To be honest, if you don't want people to use any information on your site, then you can't put it up there. If you stop them from being able to copy and paste the information, they'll still be able to take a screenshot of it, type it out and save the data that way. I know it's not the answer you're looking for, but that's just something to think about.

(I did this because i can't comment yet).


Forget it. It is not possible to block these functions in a browser. The "best" you can do is to present your data in an image or Flash movie - inconceivable, slow, impractical, horrible to implement and also circumventable using OCR software.

If all else fails, users will simply make screen shots or key in the data manually.

If you present data to your users, you will have to live with the possibility that they can copy it. End of story.

Use legal threats to prevent your contents, not technical means.


You can't ever disable it.. users can view the source of your page so the text is always available. If you put click handlers to disable right-click, they can turn javascript off..

The best you can try to do is make it inconvenient for people to deter them, but never can you prevent them.


It is impossible to secure a website against copying. There are some technices to make it more difficult, but as soon as the user has the information on his screen its already too late. He could for example take a picture with a camera if the screenshot function could be disabled somehow.

Disabling of javascript functionality (f.e. shortcuts) is not working in all browsers and the user may disable javascript.

Using programs like curl all the information on the webpage can be grabbed.

Best thing you could do is to put all the information you present into an image.


What the developers of lyrics.com have done is attach events to document.body.oncontextmenu, document.onselectstart, and document.body.onkeydown to disable the actions browsers would take.

It can be done as simply as

<body oncontextmenu="return false" onselectstart="return false"
      onkeydown="if ((arguments[0] || window.event).ctrlKey) return false">

You'd need all three; oncontextmenu basically governs right clicks, onselectstart covers drag-selecting with the mouse, and onkeydown Ctrl-key events (like someone who'd hit Ctrl+A, Ctrl+C to copy the whole page).

But I highly recommend that you NOT DO THIS. It kills usability and frustrates even legitimate users (for example people that have certain key mappings set up, or the ones who use "back" and "reload" from the context menu), and the ones you'd have to worry about would not be hindered even the slightest bit. And frankly, your content is not as special as you think it is, or you wouldn't be serving it up to any loser with a web browser. Information that valuable is not put online.

As has been noted before, all that return false stuff is not enforceable. And because i found the page particularly infuriating, that prompted me to pop up a console and dissect what they did, and detach event handlers so i could copy whatever i like and they don't even get their precious click-tracking data. Really, though, all anyone has to do is disable JavaScript.

The only way to keep people from copying text from the internet, is to keep it off the internet. Any other way is doomed to fail, as you yourself are handing them a copy as part of the very act of serving it to them.


You can stop from copy paste using below code

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


<script type="text/javascript">

function md(e) 
{ 
  try { if (event.button==2||event.button==3) return false; }  
  catch (e) { if (e.which == 3) return false; } 
}
document.oncontextmenu = function() { return false; }
document.ondragstart   = function() { return false; }
document.onmousedown   = md;

</script>
<br />


Try adding this css:

#content {
    pointer-events: none;
}

This will deactivate mouse actions, thus copy-paste too.


Disable cut, copy, and paste options.

<script language="text/javascript">
    // disable portal cut copy and paste options.
    $('body').bind('cut copy paste', function (e) {
            e.preventDefault();
    });

</script>

But I prefer to enable this option on localhost.

<script language="text/javascript">
    // disable portal cut copy and paste options.
    $('body').bind('cut copy paste', function (e) {

       // enable only localhost
       if (location.hostname === "localhost" || location.hostname === "127.0.0.1") 
        {
            return;
        }
        e.preventDefault();

    });

</script>


please try this one its working for me...

 $('body').bind('cut copy paste',function(e) {
        e.preventDefault(); return false; 
   });


With Javascript you can disable copy/cut/drag for average users who don't know how to use inspect element feature, for that just add this simple javascript code:

    document.addEventListener("copy", disable);
    document.addEventListener("cut", disable);
    document.addEventListener("drag", disable);
    document.addEventListener("dragstart", disable);
    document.addEventListener("dragover", disable);
    document.addEventListener("dragend", disable);
    document.addEventListener("drop", disable);
  
  function disable(e) {
    if (e) e.preventDefault();
    return false;
  }

If the user however tries to access the source code then you can't stop him, the best is to wrap each sentence in its own span to make it difficult for him to copy.


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


I would suggest disabling right click.

<script language="text/javascript">
    var message = "Not allowed."; 
    function rtclickcheck(keyp){ 
        if (navigator.appName == "Netscape" && keyp.which == 3){    
            alert(message); return false; 
        } 
        if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) {
            alert(message);     
            return false;
        }
    } 
    document.onmousedown = rtclickcheck;
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜