Page 1 of 1

Copy to clipboard in Javascript

PostPosted: Thu Jul 07, 2022 10:31 am
by JasonLP
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.

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>

Re: Copy to clipboard in Javascript

PostPosted: Thu Jul 07, 2022 11:36 am
by magreenblatt
The async clipboard API is not supported currently with the Alloy runtime. Use the Chrome runtime, or different approach: https://stackoverflow.com/questions/400 ... javascript