js複製內容加著作權聲明代碼

來源:互聯網
上載者:User

標籤:

1 $("body").on(‘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 />原文: <a href=‘" + document.location.href + "‘>" + document.location.href + "</a> &copy; caibaojian.com"; selection.selectAllChildren(newdiv); window.setTimeout(function () { body_element.removeChild(newdiv); }, 200); });

 

當別人複製你的文章內容時,會在文章末尾自動添加一個著作權聲明。網路著作權意識薄弱,這個是君子做法,如果真要抄你的文章,聲明再多都沒用,就像我的網站底部聲明一樣,幾乎是一個擺設,我也看開了。文章保留所有權利,如果你複製我的文章,沒有按照我的聲明,說不定哪天我心情好,就會找你聊聊天了……

代碼來源

js複製內容加著作權聲明代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.