js对文本复制操作进行内容修改

72次阅读
没有评论
<script type='text/javascript'>
function addLink() {var body_element = document.getElementsByTagName('body')[0];
    var selection;
    selection = window.getSelection();

    var pagetitle = document.getElementsByTagName('title')[0]['text'];

    var pagelink += "<br /><br /> 转载请注明来源:< a href='"+document.location.href+"'>"+document.location.href+"</ a>";

    var copy_text = selection + pagelink;
    var new_div = document.createElement('div');
    new_div.style.left='-99999px';
    new_div.style.position='absolute';
    body_element.appendChild(new_div);
    new_div.innerHTML = copy_text ;
    selection.selectAllChildren(new_div);
    
    window.setTimeout(function() {body_element.removeChild(new_div);
    },0);
}
document.oncopy = addLink;
</script>


}
正文完
有偿技术支持加微信
post-qrcode
 
评论(没有评论)
验证码