Business Development

Process driven.

Results driven.

Javascript (ES6) Copy to Clipboard in Sage-9

Last updated By

After\’a0trying a few different Javascript copy to clipboard functions (CSStricks, Sitepoint, Clipboard.js), I couldn’t get\’a0their 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\
document.querySelector('#visible-input').select();\
// Copy to the clipboard\
document.execCommand('copy');\
\};
\
\
 \
\
Here’s the HTML output:\
\

    \

  • \

  • \

\
 \
\