Copy content and add url javascript code example
Example: Copy content and add url javascript
/* block copy right*/
function addLink() {
var body_element = document.getElementsByTagName('body')[0];
var selection;
selection = window.getSelection();
var getSelection = selection + '';
var pagelink = "
اقرأ المزيد على موقع ميدطب: " + document.location.href + "
"; // change this if you want
var copytext = getSelection.substring(0, 70).concat('....') + pagelink;
var newdiv = document.createElement('div');
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';
body_element.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);
window.setTimeout(function () {
body_element.removeChild(newdiv);
}, 0);
}
document.oncopy = addLink;