Source code

Revision control

Copy as Markdown

Other Tools

<html>
<body>
<div id="content">
<div
id="testDiv"
contenteditable="true"
onpaste="handlePaste(event)"></div>
<input id="testInput" type="text" onpaste="handlePaste(event)">
</div>
<script class="testbody" type="application/javascript">
function is(a, b, msg) {
if (!Object.is(a, b)) {
throw new Error(`FAIL: expected ${b} got ${a} - ${msg}`);
}
}
function checkPasteHelper(event) {
is(event.clipboardData.getData('text/plain'), "Original text", "getData(text/plain) should return Original text");
is(event.clipboardData.types.length, 1, "Correct number of types");
}
function handlePaste(e) {
let result = null;
try {
result = checkPasteHelper(e);
} catch (e) {
result = e.toString();
}
document.dispatchEvent(new CustomEvent('testresult', {
detail: { result }
}));
}
</script>
</body>
</html>