Skip to content

Instantly share code, notes, and snippets.

@jameswestgate
Created March 25, 2015 12:08
Show Gist options
  • Save jameswestgate/a313f1536944709c73ee to your computer and use it in GitHub Desktop.
Save jameswestgate/a313f1536944709c73ee to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/vitado
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id='div' contenteditable='true' onpaste='return handlepaste(this, event)'>Existing text</div>
<script id="jsbin-javascript">
function handlepaste (elem, e) {
console.log('Detected event.clipboardData :' + e.clipboardData );
if (e.clipboardData.types) {
console.log('event.clipboardData.types');
// Look for a types property that is undefined
if (!e.clipboardData.types.length) {
console.log('event.clipboardData.types is undefined');
console.log('Manually get text/plain: ' + e.clipboardData.getData('text/plain'));
console.log('Manually get text/html: ' + e.clipboardData.getData('text/html'));
}
else {
// Loop the data store in type and display it
var i = 0;
while (i < e.clipboardData.types.length) {
var key = e.clipboardData.types[i];
var val = e.clipboardData.getData(key);
console.log((i + 1) + ': ' + key + ' - ' + val);
i++;
}
}
}
return false;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">function handlepaste (elem, e) {
console.log('Detected event.clipboardData :' + e.clipboardData );
if (e.clipboardData.types) {
console.log('event.clipboardData.types');
// Look for a types property that is undefined
if (!e.clipboardData.types.length) {
console.log('event.clipboardData.types is undefined');
console.log('Manually get text/plain: ' + e.clipboardData.getData('text/plain'));
console.log('Manually get text/html: ' + e.clipboardData.getData('text/html'));
}
else {
// Loop the data store in type and display it
var i = 0;
while (i < e.clipboardData.types.length) {
var key = e.clipboardData.types[i];
var val = e.clipboardData.getData(key);
console.log((i + 1) + ': ' + key + ' - ' + val);
i++;
}
}
}
return false;
}</script></body>
</html>
function handlepaste (elem, e) {
console.log('Detected event.clipboardData :' + e.clipboardData );
if (e.clipboardData.types) {
console.log('event.clipboardData.types');
// Look for a types property that is undefined
if (!e.clipboardData.types.length) {
console.log('event.clipboardData.types is undefined');
console.log('Manually get text/plain: ' + e.clipboardData.getData('text/plain'));
console.log('Manually get text/html: ' + e.clipboardData.getData('text/html'));
}
else {
// Loop the data store in type and display it
var i = 0;
while (i < e.clipboardData.types.length) {
var key = e.clipboardData.types[i];
var val = e.clipboardData.getData(key);
console.log((i + 1) + ': ' + key + ' - ' + val);
i++;
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment