<copy-button></copy-button>
A web-component that is not relying on Flash to copy stuff into the clipboard. Experience may vary, based on browser support, with downgrading to using prompt.
npm i --save copy-button
after which you're good to use copy-button &
You can also use it from wzrd.in CDN and drop
<script src='https://wzrd.in/standalone/copy-button@latest'></script>
into your html
After having script ran, you're good to use <copy-button></copy-button>
in your markup.
If you're not specifying inner content, it would default to 'Click to copy to clipboard', otherwise provided content would be inserted into the button. Can use icons here, etc. See example
If you specify target-text
attribute on button, provided value will be copied to clipboard. Example
If you specify target-element
attribute on button, value or text of provided DOM node will be copied to clipboard (it will be retrieved using document.getElementById
if value will be specified as #specifiedID
or document.querySelectorAll in other cases). See examples
Built on top of document.registerElement polyfill & copy-to-clipboard