Skip to content

Instantly share code, notes, and snippets.

@me-suzy
Created November 18, 2022 09:48
Show Gist options
  • Save me-suzy/37c7877fc7ff630096071f60dda2361d to your computer and use it in GitHub Desktop.
Save me-suzy/37c7877fc7ff630096071f60dda2361d to your computer and use it in GitHub Desktop.
JAVASCRIPT - READ MORE with link to website in java
<!------------READ MORE START-------->
<script type="text/javascript" >
function addLink() {
//Get the selected text and append the extra info
var selection = window.getSelection(),
pagelink = '<br /><br /> Read more at: ' + document.location.href,
copytext = selection + pagelink,
newdiv = document.createElement('div');
//hide the newly created container
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';
//insert the container, fill it with the extended text, and define the new selection
document.body.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);
window.setTimeout(function () {
document.body.removeChild(newdiv);
}, 100);
}
document.addEventListener('copy', addLink);
</script>
<!------------READ MORE END-------->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment