Javascript (ES6) Copy to Clipboard in Sage-9

After trying a few different Javascript copy to clipboard functions (CSStricks, Sitepoint, Clipboard.js), I couldn’t get their solutions working with ES6 and Sage, until I came across this article.

I stripped it down and had to change a couple things to get it working in ES6, this was my final JS ouput that I placed inside Sage/scripts/routes/common.js (init):

// Copy to clipboard example
document.querySelector('#visible-button').onclick = function copy() {
// Select the content
// Copy to the clipboard


Here’s the HTML output:


Leave a Reply