Event.clipboardData.getData has no text / html in Safari

In our application, we process the inserted content before embedding it in the content div. In Firefox and Chrome, the paste event.clipboardData.getData has two keys text / plain and text / html. In Safari, it has ~ 12 keys, which range from text to RTF, but do not include the HTML that the user pasted into any of them. How can I access this from an insert event?

$( 'div' ).on( 'paste', function( aEvent ) { var evt = aEvent.originalEvent; var text = evt.clipboardData.getData( 'text/plain' ); var html = evt.clipboardData.getData( 'text/html' ); var i, len; console.log( 'text=' + text ); console.log( 'html=' + html ); console.log( 'data types=' ); console.log( evt.clipboardData.types ); for ( i = 0, len = evt.clipboardData.types.length; i < len; i++ ) { console.log( evt.clipboardData.types[ i ] + '=' + evt.clipboardData.getData( evt.clipboardData.types[ i ] ) ); } }); 

http://jsfiddle.net/njLxk9cw/

Select both paragraphs, copy them, then paste in a new line and look at the console.

[edit] If I use Rangy range.toHtml from a copy event, I can save a snapshot of what was selected. In the paste event, I first check the clipboard, then my saved snippet, then discard the text. Ideally, I would like the clipboard API to work, if possible.

+5
source share

Source: https://habr.com/ru/post/1232209/


All Articles