Add Courtesy Link when Content Copied from Webpage using Javascript

by Sasikumar 2014-03-15 18:18:57

To add courtesy link to the content copied from the webpage:
Place the following code inside script tag,
$(document).ready(function () {
document.body.oncopy = function () {
var body = document.getElementsByTagName('body')[0];
var pagelink = "<br />Content courtesy : <a href='" + document.location.href + "'>" + document.location.href + "</a><br />";
var selected_text;
selected_text = window.getSelection();
var current_copy_text = selected_text + pagelink;
var newdiv_element = document.createElement('div');
body.appendChild(newdiv_element);
newdiv_element.innerHTML = current_copy_text;
selected_text.selectAllChildren(newdiv_element);
window.setTimeout(function () {
body.removeChild(newdiv_element);
}, 0);
};
});
1704
like
0
dislike
0
mail
flag

You must LOGIN to add comments