Ways to copy Web content to automatically add copyright information (compatible with IE, Firefox, and Chrome)

Source: Internet
Author: User
Tags add copy window
ways to copy Web content to automatically add copyright information

A search on the internet can see a lot of similar code, add the body part of the page can be.
For example, the following code:
  1. Copy content automatically add copyright information
  2. Document.body.oncopy = function ()
  3. {
  4. SetTimeout (
  5. function ()
  6. {
  7. var text = clipboarddata.getdata ("text");
  8. if (text)
  9. {
  10. Text = text + "\ r \ n Original source from" Network ", reprint please keep the original link:" +LOCATION.HREF;
  11. Clipboarddata.setdata ("text", text);
  12. }
  13. },
  14. 100
  15. )
  16. }

This code can be implemented, do not forget to write in the JS file or write directly in the page

<script = "Text/javascript" > Code </script> included.

Add the above code, someone else in your site on any page, copy any one of the text of things, paste will automatically bring the copyright information.
But the disadvantage of this code is that the test passes on the IE6, and it has no effect on Firefox or opera browsers.

In order to solve this problem, consulted a lot of experts, but also in the online search a lot of information, finally resolved, here to say, the Niang is really very powerful.

The following is a compatible code:
  1. Copy content automatically add copyright information
  2. var Sys = {};
  3. var ua = Navigator.userAgent.toLowerCase ();
  4. if (window. ActiveXObject)
  5. {
  6. Document.body.oncopy=function ()
  7. {
  8. Event.returnvalue = false;
  9. var t=document.selection.createrange (). text;
  10. var s= "\ r \ n original from [network] reprint please retain the original link:" +LOCATION.HREF;
  11. Clipboarddata.setdata (' Text ', t+ ' \ r \ n ' +s);
  12. }
  13. }
  14. Else
  15. {
  16. function Addlink ()
  17. {
  18. var body_element = document.getelementsbytagname (' body ') [0];
  19. var selection;
  20. Selection = Window.getselection ();
  21. var pagelink = "
    Original source from [the network] reprint please keep the original link: "+DOCUMENT.LOCATION.HREF;
  22. var copytext = Selection + Pagelink;
  23. var newdiv = document.createelement (' div ');
  24. newdiv.style.position= ' absolute ';
  25. newdiv.style.left= ' -99999px ';
  26. Body_element.appendchild (NEWDIV);
  27. newdiv.innerhtml = CopyText;
  28. Selection.selectallchildren (NEWDIV);
  29. Window.settimeout
  30. (
  31. function ()
  32. {
  33. Body_element.removechild (NEWDIV);
  34. },0
  35. );
  36. }
  37. Document.oncopy = Addlink;
  38. }
This code tested, can be compatible, there may be deficiencies, if found, you can leave a message, together to explore and improve.
It is best to say, pay attention to coding problems, such as the discovery of copied content added copyright information garbled, you can check the coding problem.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.