Add Read More Link When Someone Copy Paste Your Content

, , Leave a comment

Few days before when i was surfing for the latest news and I noticed(you may have also noticed that) if you copy and paste any text from the site a reference link is automatically added (at the bottom) of the copied content,which indicates the source from where you have copied that. 

I was surprised and was sure that i have copied only content then how that link also copied and then tried to figure out how it happened and how to do it. I figured out that they use a service called “Tynt“. Ya its cool but who wanted to use it.After all we are developers so i just wanted to see if we could make it happen by using JavaScript and hurray it was possible. 
One function needs to grab the copied selection, tack on a copyright notice and then add the two to the clipboard. 
<script type="text/javascript">

function addLink() {

     var body_element = document.getElementsByTagName('body')[0];

     var selection;

     selection = window.getSelection();

var pagelink = "<br /><br />
Read more at: <a href='"+document.location.href+"'>"+document.location.href+"</a>"; 

     var copytext = selection + pagelink;

     var newdiv = document.createElement('div');'absolute';'-99999px';

     newdiv.innerHTML = copytext;
     window.setTimeout(function() {
document.oncopy = addLink;

For Demo : Put the above script in head part and then just copy any content of your page and paste it in any editor.You will see an extra link for read more link is added at the bottom.
Note: Not Compatible with IE.