Last active
October 31, 2023 11:41
-
-
Save takunagai/aa1ff06283fd32b95f80f0a19f705285 to your computer and use it in GitHub Desktop.
[Copy selected text to clipboard] 選択したテキストをクリップボードにコピー #JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function copyUrlToClipboard(text) { | |
try { | |
await navigator.clipboard.writeText(text); | |
console.info('Successfully copied URL'); | |
} catch (err) { | |
console.log(err) | |
return { error: err } | |
} | |
return { success: true } | |
} | |
const textToCopy = document.getElementById('XXXX').innerText; | |
const copyButton = document.getElementById('ZZZZ'); | |
copyButton.addEventListener('click', () => { | |
copyUrlToClipboard(textToCopy); | |
alert('クリップホードにコピーしました!\nLINE でメッセージに貼り付けて編集の上、送信ください。'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment