Shopify themes, liquid, logos, and UX
How do I code a button that will copy specific text to the clipboard?
For example: <p>DISCOUNTCODE</p>, customer will click on the button, and the <p>DISCOUNTCODE</p> will be copied to the user clipboard so he/she can paste it on checkout.
Hello, I was working on a similar issue, so I thought I would post my solution. I used java to create a citation for blog articles. I am unsure where you will use your code but this may help if you are in the liquid.
<p id="sample">your conent to be copied</p>
<a class="btn btn--tertiary btn--small" href="#" onclick="CopyToClipboard('sample');return false;">Copy</a>
<script>
function CopyToClipboard(id)
{
var r = document.createRange();
r.selectNode(document.getElementById(id));
window.getSelection().removeAllRanges();
window.getSelection().addRange(r);
document.execCommand('copy');
window.getSelection().removeAllRanges();
}
</script>
You can see an example of it here at the bottom of the page https://vincenttriola.com/blogs/ten-years-of-academic-writing/hr-s-role-in-public-private-sector
Did you figure this out? I need this as a possible workaround for Dawn's silly placement of the discount code prompt in checkout.
User | RANK |
---|---|
219 | |
165 | |
65 | |
54 | |
53 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023