Created
June 2, 2023 03:38
-
-
Save ebeloded/099bb51f03d0910ddbe63e328bbb5364 to your computer and use it in GitHub Desktop.
copyPageLink
This file contains hidden or 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 copyPageLink() { | |
let pageTitle = document.title | |
let pageURL = window.location.href | |
const str = `<a href="${pageURL}">${pageTitle}</a>` | |
function listener(e) { | |
e.clipboardData.setData('text/html', str) | |
e.clipboardData.setData('text/plain', str) | |
e.preventDefault() | |
} | |
document.addEventListener('copy', listener) | |
document.execCommand('copy') | |
document.removeEventListener('copy', listener) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment