Skip to content

Instantly share code, notes, and snippets.

@hallvors
Created April 21, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hallvors/59a90f2e3816cb57f044 to your computer and use it in GitHub Desktop.
Save hallvors/59a90f2e3816cb57f044 to your computer and use it in GitHub Desktop.
Exploring queryCommandEnabled() vs onbefore* events
<pre></pre>
<script>
var pre = document.getElementsByTagName('pre')[0];
document.onbeforepaste = document.onbeforecopy = document.onbeforecut = function (e) {
pre.appendChild(document.createTextNode(e.type));
}
for(var cmd in {'copy':1, 'cut':1, 'paste':1}){
pre.appendChild(document.createTextNode('\n\n' + cmd.toUpperCase() + '\n'));
pre.appendChild(document.createTextNode('queryCommandSupported(): ' + document.queryCommandSupported(cmd) + '\n'));
try{
pre.appendChild(document.createTextNode('queryCommandEnabled(): ' + document.queryCommandEnabled(cmd) + '\n'));
}catch(e){
pre.appendChild(document.createTextNode('queryCommandEnabled throws: '+e))
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment