Disabling Copy/Paste in a Web Page

前端 未结 15 2338
心在旅途
心在旅途 2020-12-14 12:56

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

相关标签:
15条回答
  • 2020-12-14 13:37

    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.

    0 讨论(0)
  • 2020-12-14 13:37

    Try adding this css:

    #content {
        pointer-events: none;
    }
    

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

    0 讨论(0)
  • 2020-12-14 13:38

    You can stop from copy paste using below code

    <body ondragstart="return false" onselectstart="return false">
    
    0 讨论(0)
提交回复
热议问题