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:
- Copy content automatically add copyright information
- Document.body.oncopy = function ()
- {
- SetTimeout (
- function ()
- {
- var text = clipboarddata.getdata ("text");
- if (text)
- {
- Text = text + "\ r \ n Original source from" Network ", reprint please keep the original link:" +LOCATION.HREF;
- Clipboarddata.setdata ("text", text);
- }
- },
- 100
- )
- }
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:
- Copy content automatically add copyright information
- var Sys = {};
- var ua = Navigator.userAgent.toLowerCase ();
- if (window. ActiveXObject)
- {
- Document.body.oncopy=function ()
- {
- Event.returnvalue = false;
- var t=document.selection.createrange (). text;
- var s= "\ r \ n original from [network] reprint please retain the original link:" +LOCATION.HREF;
- Clipboarddata.setdata (' Text ', t+ ' \ r \ n ' +s);
- }
- }
- Else
- {
- function Addlink ()
- {
- var body_element = document.getelementsbytagname (' body ') [0];
- var selection;
- Selection = Window.getselection ();
- var pagelink = "
Original source from [the network] reprint please keep the original link: "+DOCUMENT.LOCATION.HREF;
- var copytext = Selection + Pagelink;
- var newdiv = document.createelement (' div ');
- newdiv.style.position= ' absolute ';
- newdiv.style.left= ' -99999px ';
- Body_element.appendchild (NEWDIV);
- newdiv.innerhtml = CopyText;
- Selection.selectallchildren (NEWDIV);
- Window.settimeout
- (
- function ()
- {
- Body_element.removechild (NEWDIV);
- },0
- );
- }
- Document.oncopy = Addlink;
- }
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.