Copy to clipboard in Javascript

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Copy to clipboard in Javascript

Postby JasonLP » 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.

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>
JasonLP
Mentor
 
Posts: 98
Joined: Fri Jul 25, 2014 10:10 am

Re: Copy to clipboard in Javascript

Postby magreenblatt » Thu Jul 07, 2022 11:36 am

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
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 39 guests