国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JavaScript實(shí)現(xiàn)復(fù)制文章自動(dòng)添加版權(quán)

2019-11-20 09:20:18
字體:
供稿:網(wǎng)友

第一種

<script type="text/javascript"> document.body.oncopy = function(){   setTimeout(     function (){     var text = clipboardData.getData("text");     if(text){       text = text + "/r/n本文來自: (www.survivalescaperooms.com) 詳細(xì)出處參考:"+location.href; clipboardData.setData("text", text);     }   },100) } </script> 

注意:這段代碼必須復(fù)制到 body 區(qū)域里面才能生效,放到 head 區(qū)域內(nèi)是不起作用的。

第二種

$("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 our users if (("" + selection).length < 30) 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 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 + "'>" + document.location.href + "</a> © MySite.com";   selection.selectAllChildren(newdiv); window.setTimeout(function () { body_element.removeChild(newdiv); }, 200);});

總結(jié)

以上就是小編為大家整理的兩種利用JavaScript實(shí)現(xiàn)復(fù)制文章自動(dòng)添加版權(quán)的方法,代碼很簡單,有需要的朋友們可以參考學(xué)習(xí)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 枣庄市| 临泽县| 武城县| 高雄市| 得荣县| 永胜县| 苗栗县| 永兴县| 定结县| 新民市| 腾冲县| 凤山市| 隆林| 永宁县| 海淀区| 图们市| 上高县| 琼海市| 虞城县| 阿城市| 石门县| 揭东县| 甘孜| 武安市| 天水市| 高邮市| 公安县| 汾阳市| 巧家县| 应用必备| 铜陵市| 成武县| 临泉县| 清流县| 中阳县| 漳州市| 江北区| 甘孜县| 徐水县| 呈贡县| 湾仔区|