Skip to content

Commit

Permalink
Remove deprecated execComand function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ndrsov authored Sep 18, 2022
1 parent bbf1282 commit 6885284
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions password-generator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ const randomFunc = {
}

clipboardEl.addEventListener('click', () => {
const textarea = document.createElement('textarea')
const password = resultEl.innerText

if(!password) { return }

textarea.value = password
document.body.appendChild(textarea)
textarea.select()
document.execCommand('copy')
textarea.remove()
const password = resultEl.innerText;
if (!password) {
return;
}
navigator.clipboard.writeText(password);
alert('Password copied to clipboard!')
})

Expand Down Expand Up @@ -74,4 +69,4 @@ function getRandomNumber() {
function getRandomSymbol() {
const symbols = '!@#$%^&*(){}[]=<>/,.'
return symbols[Math.floor(Math.random() * symbols.length)]
}
}

0 comments on commit 6885284

Please sign in to comment.