Copying an image to clipboard using JavaScript/jqu

2019-01-18 19:44发布

This question already has an answer here:

I need to copy an image to clipboard using JavaScript/jquery and I am using the following js to achieve that.

function copyImageToClipBoard() {
            var div = document.getElementById('chart1');
            div.contentEditable = true;
            var controlRange;
            if (document.body.createControlRange) {
                controlRange = document.body.createControlRange();
                controlRange.addElement(div);
                controlRange.execCommand('Copy');                   
            }
            div.contentEditable = false;
        }

It works fine locally in IE. But when I tried to test it from other machines IE, to paste the image into MS word I need to use the Paste Special-> Device Independent Bitmap option, otherwise I cannot see the image pasted.

I was wondering if it has anything to do with the environment of the m/c. If so is there any other option which works anywhere?

1条回答
贼婆χ
2楼-- · 2019-01-18 20:16

Clipboard access on the web is not desirable because of the security implications.

查看更多
登录 后发表回答