IDDRS/static/js/copy.js

18 lines
674 B
JavaScript
Raw Permalink Normal View History

2022-07-25 10:03:35 +00:00
// 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')
}
)
})