Copy to Clipboard in LWC
async copyApiName(){
let msg = `${this.paramString}`;
if (navigator.clipboard && window.isSecureContext) {
return navigator.clipboard.writeText(msg);
} else {
let textArea = document.createElement("textarea");
textArea.value = msg;
textArea.style.position = "fixed";
textArea.style.left = "-999999px";
textArea.style.top = "-999999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
return new Promise((res, rej) => {
document.execCommand("copy") ? res() : rej();
textArea.remove();
});
}
}
Comments
Post a Comment