JS复制图片文字到剪切板

function CopyImage(img) {
    if (img.tagName != 'IMG')
        return;
    if (typeof img.contentEditable == 'undefined')
        return;
    if (!document.body.createControlRange)
        return;
    var ctrl = document.body.createControlRange();
    img.contentEditable = true;
    ctrl.addElement(img);
    ctrl.execCommand('Copy');
    img.contentEditable = false;
    alert('复制图片完成');
}

function CopyToClipBoard(){
    var clipBoardContent="abcdefg";
    window.clipboardData.setData("Text",clipBoardContent);
    alert('复制文字完成');
}

作者:达奇
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/dachie/p/1875529.html