<div class="example">
<button id="readCB">Read Clipboard</button>
<div id="log"></div>
<p>If this doesn't work for you <a href="https://codepen.io/pen/debug/OJeXgOL" target="_blank">try Debug Mode</a>.</p>
</div>
body {
height: 100vh;
margin: 0;
display: grid;
place-items: center;
background: #455a64;
font-family: monospace;
}
.example {
background: white;
border-radius: 12px;
overflow: clip;
width: 75dvi;
}
#readCB {
margin: 2rem;
}
#log {
background: black;
color: white;
padding: 2rem;
}
p {
text-align: center;
padding-inline: 1rem;
}
let $log = document.querySelector("#log");
document.querySelector("#readCB").addEventListener("click", async () => {
let contents = await navigator.clipboard.readText();
console.log(contents);
$log.innerText = contents;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.