First Kind
<script type= "Text/javascript" >
document.body.oncopy = function () {
settimeout (
function ()
{ var text = clipboarddata.getdata ("text");
if (text) {
text = text + \ r \ n This article is from: (www.jb51.net) Detailed source reference: "+LOCATION.HREF; Clipboarddata.setdata (" text ", text);
}
},100)
}
Note: This code must be copied into the body area in order to take effect, and it will not work in the head area.
Second Kind
$ ("body"). Bind (' Copy ', function (e) {if (typeof window.getselection = = "undefined") return//IE8 or earlier ... var
Body_element = document.getElementsByTagName (' body ') [0];
var selection = Window.getselection ();
If the selection is short let's not annoy we users if (("" + selection). length < return; Create a div outside of the visible area//and fill it with the selected text var newdiv = document.createelement (' div
');
newdiv.style.position = ' absolute ';
Newdiv.style.left = ' -99999px ';
Body_element.appendchild (NEWDIV);
Newdiv.appendchild (selection.getrangeat (0). Clonecontents ());
We need a <pre> tag workaround//otherwise The text inside "pre" loses all of the line breaks! if (selection.getrangeat (0). Commonancestorcontainer.nodename = = "PRE") {newdiv.innerhtml = "<pre>" +
newdiv.innerhtml + "</pre>"; } newdiv.innerhtml + + <br/><br/>read more at: <a href= ' "+ document.location.href +" ' > "+ docum Ent.locatioN.href + "</a>©mysite.com";
Selection.selectallchildren (NEWDIV);
Window.settimeout (function () {body_element.removechild (newdiv);}, 200); });
Summarize
The above is a small series for everyone to organize the use of JavaScript to achieve the copy automatically add copyright method, the code is very simple, the need for friends can refer to learning.