IDDRS/static/js/copy.js
2022-07-25 12:03:35 +02:00

18 lines
674 B
JavaScript

// get the text from the DOM Element:
const textToCopy = document.querySelector('#url').innerText
// when someone clicks on the <a class="copy-text"> element
// (which should be a <button>), execute the copy command:
document.querySelector('#copyURL').addEventListener('click' , ()=> {
navigator.clipboard.writeText(textToCopy).then(
function() {
/* clipboard successfully set */
// window.alert('Success! The text was copied to your clipboard')
document.getElementById("copyURL").value = "Copied!";
},
function() {
/* clipboard write failed */
window.alert('Opps! Your browser does not support the Clipboard API')
}
)
})