I have the following function:
function openurl(){
navigator.clipboard.writeText("TextToCopy");
window.open('url');
}
executing in this:
<button onclick=openurl()>Openurlbutton</button>
It only opens the window and does not copy the text. I am so lost.. help :D
CodePudding user response:
navigator.clipboard.writeText is an async function. For you to work you can edit your code to the following. (https://www.w3.org/TR/clipboard-apis/#async-clipboard-api)
async function openurl() {
await navigator.clipboard.writeText('TextToCopy');
window.open('url');
}