Disable copying data from webpage

前端 未结 10 1922
情歌与酒
情歌与酒 2020-12-18 09:52

I was looking for any way to create web page,so that user wont be able to copy content from my web page. i.e. User wont be able to select the any text present on the webpag

相关标签:
10条回答
  • 2020-12-18 10:24

    You can disable the selection, and with out selection you do not have copy/paste, however I suggest do that only on some parts of your page because is frustrate for the user.

    This is the simple code that you can do that, eg, if you have a div with id="notme", run the disableSelOnThis("notme");

        function disableSelOnThis(IdName) {
            var oElem = document.getElementById(IdName);
            if (oElem)
                disableSelection(oElem); }
    
        function disableSelection(element) {
            element.onselectstart = function() {
                return false;
            };
    
            element.unselectable = "on";
            element.style.MozUserSelect = "none";
            element.style.cursor = "default";   
        }  
    

    The code was from : http://ajaxcookbook.org/disable-text-selection/ , but its seams that this site is not longer live.

    Of course without javascript enable this is not working and everything ChrisF says still stands.

    0 讨论(0)
  • 2020-12-18 10:34

    You can add to your body tag like so:

    <body onselectstart="return false">
    
    0 讨论(0)
  • 2020-12-18 10:38

    You can use user-select CSS3 propertie

    HTML like this :

    <span class="protected">Datas you wants protect</span>
    

    And the correspondant CSS :

    .protected {
        -moz-user-select:none;
        -webkit-user-select:none;
        user-select:none;
    }
    

    See my example : http://jsfiddle.net/DoubleYo/RPv4q/

    This solution is not cross browser but work fine with firefox and chrome/safari

    EDIT : advanced user can copy your content with view the page source, make pdf or print your page, and some people mention firebug, fiddler.

    0 讨论(0)
  • 2020-12-18 10:39

    Ultimately you can't.

    If you disable the ability to select text, the context menu or even just the copy option from the context menu users will still be able to see your content.

    If they can see it they can copy it:

    • Take a screenshot.
    • Take a photo.
    • Type the text they see into Notepad.
    • Dictate the text into a recorder.

    It's not worth the development effort and you won't stop the determined copier. All you'll end up doing is annoying your legitimate users.

    Add value to your site so people want to keep coming back rather than just taking content and running. This could be:

    • Allow user generated content to expand on what's there.
    • Update content regularly so it's always fresh.
    0 讨论(0)
提交回复
热议问题