Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save garrettr/ad29d0d32e88a0bd4f43 to your computer and use it in GitHub Desktop.
Save garrettr/ad29d0d32e88a0bd4f43 to your computer and use it in GitHub Desktop.
document.queryCommandSupport('copy') needs to be user-initiated in Chrome, but not in Firefox
<!doctype html>
<html>
<head>
<title>Test document.queryCommandSupported</title>
</head>
<body>
<p id="copySupportedNonUserInititated"><code>document.queryCommandSupported('copy')</code> (non user-initiated): <span id="copySupportedNonUserInitiatedResult"></span></p>
<p id="copySupportedUserInitiated"><code>document.queryCommandSupported('copy')</code> (user-initiated): <span id="copySupportedUserInitiatedResult"></span></p>
<button id="testCopySupportedUserInitiated">Click me to test user-initiated document.queryCommandSupported</button>
<script type="text/javascript">
var copySupportedNonUserInitiated = document.queryCommandSupported('copy');
document.querySelector('#copySupportedNonUserInitiatedResult').innerHTML = copySupportedNonUserInitiated;
var testButton = document.querySelector('#testCopySupportedUserInitiated');
testButton.addEventListener('click', function () {
var copySupportedUserInitiated = document.queryCommandSupported('copy');
document.querySelector('#copySupportedUserInitiatedResult').innerHTML = copySupportedUserInitiated;
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment