Remove deprecated execComand function

Document.execCommand() has been deprecated and altthough some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes, my alternative uses instead the Clipboard API to copy the generated password to the clipboard
This commit is contained in:
Andrés Soria 2022-09-18 14:20:32 -05:00 committed by GitHub
parent bbf12821ce
commit 688528440b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,16 +15,11 @@ const randomFunc = {
} }
clipboardEl.addEventListener('click', () => { clipboardEl.addEventListener('click', () => {
const textarea = document.createElement('textarea') const password = resultEl.innerText;
const password = resultEl.innerText if (!password) {
return;
if(!password) { return } }
navigator.clipboard.writeText(password);
textarea.value = password
document.body.appendChild(textarea)
textarea.select()
document.execCommand('copy')
textarea.remove()
alert('Password copied to clipboard!') alert('Password copied to clipboard!')
}) })