I am attempting to copy text content from an iframe using javascript. I have code almost identical to the accepted answer for this question How can I copy text in one click in Mozilla Firefox? however it no longer seems to work.
It works fine on Safari, Chrome and IE. In FF the selecting works fine, but I am getting the following error on the console:
document.execCommand(‘cut’/‘copy’) was denied because it was not called from inside a short running user-generated event handler.
The problem is, just like the accepted answer in the question above, I am in a user-generated event handler.
In recent versions of FF clipboard events should available by default, I have checked that they are enabled but no joy.
Has anyone encountered any issues like this recently?
EDIT
Adding code snippet. Its a little ugly due to iframe
(function() {
var el = document.getElementById("copyButton");
el.addEventListener("click", selectAllText, false);
})();
function selectAllText(){
var window;
// Google Chrome Iframe
if(noteViewFrame.contentWindow){
window = noteViewFrame.contentWindow;
}else {
// Other browsers
window = noteViewFrame;
}
window.makeSelectable();
var node = window.document.getElementById( 'NoteEditor_0' );
if ( window.document.selection ) {
var range = window.document.body.createTextRange();
range.moveToElementText( node );
range.select();
} else if ( window.getSelection ) {
var range = window.document.createRange();
range.selectNodeContents( node );
window.getSelection().removeAllRanges();
window.getSelection().addRange( range );
}
window.document.execCommand('copy');
}
Event is triggered, contents are selected, but on FF the above error is shown in the console