最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - No Copy Script for html page - Stack Overflow

programmeradmin2浏览0评论

One of my clients would like a No Copy Script on there website to prevent people copying the text off the page. Is there a cross browser way you can do this? I would probably just look at a JavaScript method. I know this can be turned off by people with a bit of knowhow but will do for most cases.

One of my clients would like a No Copy Script on there website to prevent people copying the text off the page. Is there a cross browser way you can do this? I would probably just look at a JavaScript method. I know this can be turned off by people with a bit of knowhow but will do for most cases.

Share Improve this question edited Jul 15, 2010 at 8:29 Veger 37.9k11 gold badges108 silver badges117 bronze badges asked Jul 15, 2010 at 8:27 LindaLinda 2,2475 gold badges30 silver badges40 bronze badges 3
  • 4 I'm adding this as a ment, rather than an answer, because it's not answering the question you're asking, but,... If you can do anything to dissuade your client from going down this route, please do. There's nothing more frustrating as an end user, as I'm sure you're well aware :), than websites that don't allow you to copy text out, be it to make a note of something, to save a URL for later, etc,... Do your client a favour and try to show them the error of their ways, if possible :-) – Rob Commented Jul 15, 2010 at 8:33
  • I'd like to second what Rob said, and also note that you can't stop end users from disabling JavaScript or using Greasemonkey and ignoring your restrictions. – Borealid Commented Jul 15, 2010 at 8:39
  • I also agree. They have a big site with information and want people to pay to copy the information off it. I think they would be better giving away free content and having a members area with more content there. – Linda Commented Jul 15, 2010 at 8:45
Add a ment  | 

4 Answers 4

Reset to default 3

There are ton of resources on the Internet about this request. Mind that a determined user will always be able to copy the text from a webpage.

<script language="JavaScript"> 
// distributed by http://hypergurl. <!-- var popup="Sorry, right-click 
is disabled.\n\nThis Site Copyright ©2000"; function noway(go) { if 
(document.all) { if (event.button == 2) { alert(popup); return false; } } if (document.layers) 
{ if (go.which == 3) { alert(popup); return false; } } } if (document.layers) 
{ document.captureEvents(Event.MOUSEDOWN); } document.onmousedown=noway; // --> 
</script>



<script language="JavaScript1.1"> 
// distributed by http://www,hypergurl. <!-- var debug = true; function 
right(e) { if (navigator.appName == 'Netscape' && (e.which == 3 || e.which 
== 2)) return false; else if (navigator.appName == 'Microsoft Internet Explorer' 
&& (event.button == 2 || event.button == 3)) { alert('This Page is fully 
protected!'); return false; } return true; } document.onmousedown=right; if (document.layers) 
window.captureEvents(Event.MOUSEDOWN); window.onmousedown=right; //--></script>

Not an answer but this what I think about the subject:

If you want people not to copy content of your site then don't post it on the Internet. javascript will prevent the user from selection but the users will be annoyed. (e.g. I sometimes select text to make the reading easier, instead of copying it)

People will still get the text via the HTML source/DOM. People can retype the text or make a picture and use OCR.

<script language=JavaScript>
  var message="!!YOU CANNOT COPY ANY TEXT OR IMAGE FROM THIS SITE!";
  function clickIE4()
  {
    if (event.button==2)
    {
      alert(message);
      return false;
    }
  }
  function clickNS4(e)
  {
    if (document.layers||document.getElementById&&!document.all)
    {
      if (e.which==2||e.which==3)
      {
        alert(message);
        return false;
      }
    }
  }

  if (document.layers)
  {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
  }
  else if (document.all&&!document.getElementById)
  {
    document.onmousedown=clickIE4;
  }
  document.oncontextmenu=new Function("alert(message);return false")
</script>
</head>
<body>
发布评论

评论列表(0)

  1. 暂无评论