Copy to clipboard in Javascript
Posted: Thu Jul 07, 2022 10:31 am
I've searched through the threads but have found nothing concrete on this topic. I am trying to allow copy-to-clipboard functionality via javascript. The following page works in a browser (Displays "OK" and verified that text is actually in the clipboard), but when run in CEF it fails (Displays "Failed" and verified that text has not been copied to clipboard).
FWIW This also fails when running in the sample cefclient application.
FWIW This also fails when running in the sample cefclient application.
- Code: Select all
<body>
<button onclick="javascript:copyToClipboard()">Copy</button>
<div id="result"></div>
</body>
<script language = "javascript">
function copyToClipboard() {
navigator.clipboard.writeText("Hello World").then(function() {
document.getElementById("result").textContent="OK";
}, function(err) {
document.getElementById("result").textContent="Failed";
});
}
</script>