Cannot use `document.execCommand(‘copy’);` from developer console

document.execCommand(‘copy’) must be triggered by the user. It’s not only from the console, it’s anywhere that’s not inside an event triggered by the user. See below, the click event will return true, but a call without event won’t and a call in a dispatched event also. console.log(‘no event’, document.execCommand(‘bold’)); document.getElementById(‘test’).addEventListener(‘click’, function(){ console.log(‘user click’, document.execCommand(‘copy’)); }); … Read more

Javascript trick for ‘paste as plain text` in execCommand

It will intercept the paste event, cancel the paste, and manually insert the text representation of the clipboard: http://jsfiddle.net/HBEzc/. This should be the most reliable: It catches all kinds of pasting (Ctrl+V, context menu, etc.) It allows you to get the clipboard data directly as text, so you don’t have to do ugly hacks to … Read more