After a helpful comment on my previous question: Copy & Paste plain text within HTML
I'm now struggling to apply this approach to a rich text editor (RTE). My application runs in a CMS environment, CQ5.6.1 in this case, but this shouldn't be relevant to the problem. Text blocks are edited within this system by double clicking on it, which opens a so called dialog where within the first tab the RTE is loaded in an iframe. So the iframe will be added to the DOM after a user interaction. How can I attach the paste event listener to this iframe?
I tried this at first.
jQuery(document, jQuery('iframe').contents()).on('paste', paste);
I can see that this approach won't work as the iframe isn't there when I call this method. So I tried to attach the load event on any added iframe. At least I though on
would take care of this...
jQuery(document).on('paste', paste);
jQuery('iframe').on('load', function() {
jQuery(this).contents().on('paste', paste);
});
But event the load
event never gets fired. What am I doing wrong or is there a more elegant way?
EDIT: I also tried a third approach but still the load event never gets fired:
jQuery(document).on('load', 'iframe', function() {
jQuery(this).contents().on('paste', paste);
});