Skip to content

Commit

Permalink
add click on password to copy in buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
gusevgrishaem1 committed Nov 9, 2024
1 parent 2d8a558 commit bb52c6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ function generatePassword() {
}

document.getElementById('password').value = password;
}
}

document.getElementById("password").addEventListener("click", function(){
const passwordField = document.getElementById("password");
passwordField.select();
passwordField.setSelectionRange(0, 99999);
navigator.clipboard.writeText(passwordField.value)
.then(() => {
alert('Password copied to clipboard!');
})
.catch(err => {
console.error('Failed to copy password: ', err);
alert('Failed to copy password.');
});
})
1 change: 1 addition & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ h1 {
width: 100%;
text-align: center;
box-sizing: border-box;
cursor: pointer;
}

.password:focus {
Expand Down

0 comments on commit bb52c6e

Please sign in to comment.