Creating a copy to clipboard button in Webflow to dynamically copy the link of a CMS item is possible using a combination of Webflow settings and custom script. Here's how you can achieve it:
data-url and the Value is the dynamic CMS URL. This can be done by linking the Value to the item's URL field.
Here is a sample script to guide you:
document.querySelectorAll('.your-button-class').forEach(button => {
button.addEventListener('click', function() {
const url = this.getAttribute('data-url');
navigator.clipboard.writeText(url).then(() => {
alert('Link copied to clipboard!');
}).catch(err => {
console.error('Error copying to clipboard:', err);
});
});
});
To dynamically enable a copy to clipboard function for each CMS item’s link in Webflow, add a button within each item that includes a data attribute with the URL. Use a script to copy that attribute's value to the clipboard when the button is clicked.