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

Popular posts from this blog

Custom List View Button In Salesforce

Get Record Id RecordId in LWC

PDF LWC (Link for pdf liabrary)