Created
February 18, 2020 12:15
-
-
Save Ashkanph/60227e4b728eb2c4a6221f9f34ffe6c6 to your computer and use it in GitHub Desktop.
copyright clipboard select copy
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
// Source: https://www.thepunctuationguide.com/js/copyright.js | |
function addLink() { | |
var selection = window.getSelection(), | |
pagelink = '<br /><br /> From ' + document.location.href + '<br />© 2020 thepunctuationguide.com', | |
copytext = selection + pagelink, | |
newdiv = document.createElement('div'); | |
newdiv.style.position = 'absolute'; | |
newdiv.style.left = '-99999px'; | |
document.body.appendChild(newdiv); | |
newdiv.innerHTML = copytext; | |
selection.selectAllChildren(newdiv); | |
window.setTimeout(function () { | |
document.body.removeChild(newdiv); | |
}, 100); | |
} | |
document.addEventListener('copy', addLink); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment