Skip to content

Commit

Permalink
Use the Clipboard API
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kastl <[email protected]>
  • Loading branch information
dkastl committed Oct 1, 2024
1 parent 7b58b9a commit cf291d2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ async function generateQRCode(): Promise<void> {
*/
function copyUrlToClipboard(): void {
const urlField = document.getElementById('generatedUrl') as HTMLInputElement;
urlField.select();
document.execCommand('copy');
alert('URL copied to clipboard!');

// Use the Clipboard API to copy the URL
navigator.clipboard.writeText(urlField.value)
.then(() => {
alert('URL copied to clipboard!');
})
.catch(err => {
console.error('Failed to copy text: ', err);
alert('Failed to copy URL');
});
}

0 comments on commit cf291d2

Please sign in to comment.