From 6f586375250ab8e8310e96a42c5a5266010edb0d Mon Sep 17 00:00:00 2001 From: alwenpy Date: Mon, 8 Apr 2024 14:39:51 +0530 Subject: [PATCH] solved the issue #13 Signed-off-by: alwenpy --- bug-hercules/Password_generator/index.html | 2 +- bug-hercules/Password_generator/js/script.js | 31 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/bug-hercules/Password_generator/index.html b/bug-hercules/Password_generator/index.html index 272b4a3..70d1d8f 100644 --- a/bug-hercules/Password_generator/index.html +++ b/bug-hercules/Password_generator/index.html @@ -22,7 +22,7 @@

Password Generator

- diff --git a/bug-hercules/Password_generator/js/script.js b/bug-hercules/Password_generator/js/script.js index a092fbf..d41cc35 100644 --- a/bug-hercules/Password_generator/js/script.js +++ b/bug-hercules/Password_generator/js/script.js @@ -165,6 +165,37 @@ function generatePassword(){ handleSlider(); } + function copyPassword() { + // Select the password display element + passwordDisplay.select(); + // Copy the selected text + document.execCommand("copy"); + // Deselect the text + window.getSelection().removeAllRanges(); + + + copyMsg.classList.remove("hide"); + setTimeout(() => { + copyMsg.classList.add("hide"); + }, 2000); + alert('Password copied to clipboard'); + } + + // Add event listener to the copy button + copyBtn.addEventListener('click', copyPassword); + +// function copyPassword(password){ +// var tempInput = document.createElement("input"); + +// tempInput.value = password; +// tempInput.setAttribute("readonly", ""); +// document.body.appendChild(tempInput); +// tempInput.select(); +// tempInput.setSelectionRange(0, tempInput.value.length); + +// document.execCommand("copy"); +// document.body.removeChild(tempInput); +// } // remove the previous password if (password.length) password = "";