SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    Zero Point Zero Siebird's Avatar
    Join Date
    Feb 2007
    Location
    York, PA
    Posts
    456
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to disable copy/paste with jQuery

    Hi,
    Easy question...I can't figure out how to disable clipboard on a specific element using jQuery. I have the context menu disabled on right click, but can't figure out how to disable the clipboard?

    Disable context menu:
    Code JavaScript:
    $('#recentUsers').bind("contextmenu",function(e){
    	return false;
    });

  2. #2
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    {element}.oncontextmenu=function(){return false;};
    You aren't allowed to disable the clipboard in current versions of opera.

  3. #3
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't disable the user's clipboard.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  4. #4
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't disable the user's clipboard.
    Wrong.

  5. #5
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bals28mjk View Post
    Wrong.
    An example please? You think it's possible to actually DISABLE the user's clipboard from the web? It may be possible to hijack it or empty it but I really don't think that disabling it completely is possible! Prove me wrong.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  6. #6
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha.

    If I were wanting to disable the context menu for the entire document I'd do something like:
    Code:
    onload=function(){
    document.oncontextmenu=function(){return false;}
    }
    Cheers.

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,252
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Although you may have limited success disabling right-click (This is controlled by the browser, not script in the page. That is, does the browser allow script to disable the context menu?), copy-paste is even further outside the realm of the page and control belongs more to the OS (as it involves memory). IMO, it is even more pointless to try to hi-jack the OS than it is trying to hi-jack the browser. Whatever the reasoning behind your wanting to do this is, I'm sure there's a better way to approach the problem.

  8. #8
    Zero Point Zero Siebird's Avatar
    Join Date
    Feb 2007
    Location
    York, PA
    Posts
    456
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    ...Whatever the reasoning behind your wanting to do this is, I'm sure there's a better way to approach the problem.
    I want to "secure" the content within a specific div. So a user can't steal the copy, thus disabling copy/paste. Or maybe even a message box saying this "copyrighted content blah blah blah..."

  9. #9
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @bals28mjk, you've only shown how to disable the context menu... The clipboard will still be able to operate.

    @Siebird, there is NO way to fully secure any content which you serve on the web. (apart from authorization systems / password etc.). Disabling the context menu does not make it impossible to grab your content. Even if you did manage to disable the clipboard (impossible) it would still be possible for anyone to grab your "protected" content...
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  10. #10
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to "secure" the content within a specific div. So a user can't steal the copy, thus disabling copy/paste. Or maybe even a message box saying this "copyrighted content blah blah blah..."
    If the user knows what they're doing, it's impossible to prevent that. They can simply disable JavaScript.

  11. #11
    Zero Point Zero Siebird's Avatar
    Join Date
    Feb 2007
    Location
    York, PA
    Posts
    456
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JimmyP View Post
    @Siebird, there is NO way to fully secure any content which you serve on the web. (apart from authorization systems / password etc.). Disabling the context menu does not make it impossible to grab your content. Even if you did manage to disable the clipboard (impossible) it would still be possible for anyone to grab your "protected" content...
    Yep, I wasn't sure if it was possible or not
    Quote Originally Posted by bals28mjk View Post
    If the user knows what they're doing, it's impossible to prevent that. They can simply disable JavaScript.
    Yeah I know, or just look at the source code.

    Thanks all for the info. I'll relay the message to the client

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Even though it's not possible to completely protect things, it may not be a bad idea to implement some of the techniques. You won't be able to protect if from everyone but your typical visitor won't be able to do anything about it.

    Be careful though with such techniques though, because you're likely to annoy the visitor if they do want to copy things for a lawful purpose, and they may not want to come back to your site if they feel they're going to be annoyed by such trivialities.

    What am I trying to say? Go ahead with it if you want, but make yourself aware of how the consequences will affect things for your visitors and their perception of the site.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another technique to consider would be to disable the copy shortcut on the keyboard with key code detecting.

    I don't think it's a bad idea to consider any of these methods, but keep in mind any user with printscreen and a crop tool can easily grab your image.

    Also, another option would be to watermark your graphics.

    Cheers.

  14. #14
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,252
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Theft of copyrighted content is definately a legitimate concern. The problem is that if it's made available online, it can be stolen. You can limit access to it so only registered visitors can see it. You can limit HTTP access so it can't be hot-linked. But ultimately the only viable solution is to take (somewhat costly) legal action against violators.

    That said, you should make it abundantly clear and obvious that the content is copyrighted. A "this content is copyrighted" notice is good. And rather than disabling right-click, you could have a right-click alert over the content that states it's copyrighted. You could also z-index a transparent image (element?) over the content so it can't receive focus. Using javascript and CSS to make things more difficult for thieves isn't foolproof, and as pmw57 mentioned, you don't want to PO visitors, but it can help prove intent.

    Maybe instead of using text, you could use an image of the text? The aesthetic quality may suffer and OCR may still be able to get the text out of the image, but the text could not be simply "selected" via right-click, menu bar, keyboard, or view-source.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •