彰化一整天的論壇

 找回密碼
 立即註冊
查看: 17|回復: 0

【轉貼】網頁複製內容自動加上出處

[複製鏈接]
發表於 3 天前 | 顯示全部樓層 |閱讀模式

轉貼: add Source Link or Copyright Note When Someone Copies Text
  1. function addLink() {
  2.     //Get the selected text and append the extra info
  3.     var selection = window.getSelection();
  4.     pagelink = ". Read more at: " + document.location.href;
  5.     copytext = selection + pagelink;
  6.         //Create a new div to hold the prepared text
  7.     newdiv = document.createElement('div');

  8.     //hide the newly created container
  9.     newdiv.style.position = 'absolute';
  10.     newdiv.style.left = '-99999px';

  11.     //insert the container, fill it with the extended text, and define the new selection
  12.     document.body.appendChild(newdiv);
  13.     newdiv.innerHTML = copytext;
  14.     selection.selectAllChildren(newdiv);

  15.     window.setTimeout(function () {
  16.         document.body.removeChild(newdiv);
  17.     }, 100);
  18. }
  19. document.addEventListener('copy', addLink);

  20. //****************************************
複製代碼
文章來源: https://techwelkin.com/add-sourc ... pied-text-clipboard
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

 ㄚ母滴雞湯
 員林香純滴雞精

Archiver|手機版|小黑屋|彰化一整天的論壇(Excel,Office)

GMT+8, 2021-2-26 15:26 , Processed in 0.094181 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回復 返回頂部 返回列表