How do I set the button to copy code to clipboard? (QAB)

If you would like the button in your Quick Announcement Bar to copy text, such as a promo code, to your customer's clipboard, you can do so with manual coding. This will replace the hyperlink function, so instead of redirecting your customer to another page, they'll copy text to their clipboard.




Place this text into the Custom Code section:


<script type="text/javascript">

document.getElementById("qab_button").onclick = CopyCode;

function CopyCode() {

navigator.clipboard.writeText("CustomCodeText").then(() => {

alert("Successfully copied promo code");

})

.catch(() => {

alert("Error. Code cannot be copied.");

});

}

</script>



Then replace "CustomCodeText" (the red text above) with text you'd like your customers to copy. Remember to keep your text inside quotation marks. For example:


navigator.clipboard.writeText("promo2025").then(() => {





It should look something like this in the end:





This will copy the text 'promo2025' to the clipboard and alert the customer that the code has been copied.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.