网页复制内容追加到剪切板

function addLink() {
            let body_element = document.body;
            let selection = window.getSelection();
            let locationHref = document.location.href;
            let appendLink = "

 原文出自[ ushowtime ] 转载请保留原文链接: <a href='" + locationHref + "'>" + locationHref + "</a>";
            if (window.clipboardData) { // Internet Explorer
                let copytext = selection + appendLink;
                window.clipboardData.setData("Text", copytext);
                return false;
            } else {
                let copytext = selection + appendLink;
                let 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);
            }
        }
原文地址:https://www.cnblogs.com/ushowtime/p/14878127.html