I am trying to copy the content of the editor to the clipboard when clicking a button on a different part of the screen. When the page loads and the button is clicked, the selectAll command works, but the copy command does not. However, the 2nd time the button is clicked, it all works correctly. I'd rather not have to program phantom button clicks to resolve this. I am new to CKEditor, but this seems like a timing or scope issue. Any help is greatly appreciated.
Here is my code:
<html> <head> <script type="text/javascript" src="ckeditor/ckeditor.js"></script> <script type="text/javascript"> var g_editorObj = new Object; window.onload = function () { g_editorObj = CKEDITOR.replace('editor1'); } function doCopyClipBoard() { try { g_editorObj.focus(); g_editorObj.execCommand("selectAll"); g_editorObj.execCommand("copy"); //g_editorObj.on('afterCommandExec', handleCopy); } catch (ex) { alert(ex.Message); } } function handleCopy() { g_editorObj.execCommand("copy"); } </script> </head> <body> <input type="button" onclick="doCopyClipBoard()" value="Copy" /><br /> <textarea id="editor1" name="editor1" rows="10" cols="80">Testing this thing</textarea> </body> </html>