Skip to content

Instantly share code, notes, and snippets.

@endtwist
Created January 18, 2012 04:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endtwist/1630921 to your computer and use it in GitHub Desktop.
Save endtwist/1630921 to your computer and use it in GitHub Desktop.
Paste event in Safari
// Safe to say...textarea is a good idea: <textarea id="pasteField"></textarea>
$( '#pasteField' ).on( 'paste', function( evt ) {
// Safari has a weird "types" list that we need to loop through and no "items" array.
var i = 0, items = [], item, key = 'text/plain', kind = 'string';
while (i < evt.originalEvent.clipboardData.types.length) {
var key = evt.originalEvent.clipboardData.types[i];
if( !key.match( /(text\/)|(plain-text)/i ) ) {
kind = 'file';
}
items.push( { kind: kind, type: key } );
i++;
}
// Let's just get content of the first item.
item = items[0];
console.log( evt.originalEvent.clipboardData.getData( item.type ) );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment