Add a Link to Source to Copied Text

On many on-line news sited noticed that if you copy and paste any text from the site a reference link appears at the bottom, indicating the source. That functionality could be implemented pretty easily using JavaScript. Add a Copyright Notice to Copied Text article describes you how to do it.

All that is needed is to write a function that registers to copy action, grabs the copied selection text, adds on a copyright notice and then send those two to the clipboard. Just add this code between your page’s head tag (works also inside body section).

<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='"+
            "</a><br />"; // change this as you need
	var copytext = selection + pagelink;
	var newdiv = document.createElement('div');'absolute';'-99999px';
	newdiv.innerHTML = copytext;
	window.setTimeout(function() {
document.oncopy = addLink;

This seems to work well on Firefox and according to original article also with most other browsers. Sorry IE people, this one won’t work for you.

This is already in use in documents section. Go to any document and try cut+paste from any document there.


  1. hardwoodfloorrefinishers says:

    Really a very nice blog.
    I will surely bookmark this.

  2. 1v1 lol says:

    Ahh that is incredible bless your heart! Useful for extraordinary requirements as well!


Leave a Comment

Your email address will not be published. Required fields are marked *