Skip to content

Instantly share code, notes, and snippets.

@jaredly
Last active December 16, 2016 01:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jaredly/76ea78ae3633722d41f734dea49c3003 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>onpaste</title>
</head>
<body>
<div id="root"></div>
<script>
const log = txt => {
const div = document.createElement('div')
document.body.appendChild(div)
div.innerText = txt
}
const makeTxt = () => {
const txt = document.createElement('textarea')
document.body.appendChild(txt)
return txt
}
document.body.addEventListener('paste', function(e) {
[].map.call(e.clipboardData.items, item => {
log(item.kind + ' : ' + item.type)
const txt = makeTxt()
item.getAsString(ss => txt.value = ss)
})
});
</script>
<div>paste here
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment