ExecCommand ("copy") does not work in IE when the user responds to the invitation with the "Do not allow" command,

If, when execcommand ('copy') is executed, the security level is set to at least "Medium" in IE (checked in Edge and 11), the browser asks you if you are allowed to allow the page to manipulate your clipboard.

My problem is that if you click "Do not allow", execCommand ("copy") still returns true . In addition, no errors occur.

How can I catch and process this user response?

+7
internet-explorer copy execcommand
source share
1 answer

This is an older question, but I will call as I stumbled upon this problem myself.

As a result, I used the fact that IE supports the document.execCommand('paste') method. However, you can paste this copied material into hidden input and check it for content that should have been copied.

If the user allowed to manipulate the clipboard, the inserted content and the copied content will be the same. Otherwise, they will not be. Something like that:

 var copySuccess, canPaste; inputElementToCopy.select(); copySuccess = document.execCommand('copy'); inputElementToPaste.select(); canPaste = document.execCommand('paste'); if (canPaste) { copySuccess = inputElementToPaste.value === inputElementToCopy.value; // Since IE supports paste, // if user allowed clipboard: copySuccess === true // else: copySuccess === false } 
0
source share

All Articles