js复制带版权链接代码

Js 2019-10-23 23:37:36 评论
function addLink() {
    var body_element = document.body;
    var selection;
    var blogName = '【淮安SEO www.huaianseo.cn】'; // 此处修改成你自己网站的名称
    selection = window.getSelection() ? window.getSelection() : document.selection.createRange().text;
    if (window.clipboardData) { // Internet Explorer
        var pagelink ="<br>————————————————————————————————<br>文章来源"+blogName+" 转载请保留链接: "+document.location.href+"";
        var copyText = selection + pagelink;
        window.clipboardData.setData ("Text", copyText);
        return false;
    } else {
        var pagelink = "<br>————————————————————————————————<br>文章来源"+blogName+" 转载请保留链接: "+document.location.href+"";
        var copyText = selection + pagelink;
        var 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);
    }
}
document.oncopy = addLink;

评论

说点什么吧
  • 全部评论(0
    还没有评论,快来抢沙发吧!