Answers for "Copy content and add url javascript"

0

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 = "<br /><br /> اقرأ المزيد على موقع ميدطب: <a href='" + document.location.href + "'>" + document.location.href + "</a><br />"; // 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;
Posted by: Guest on May-04-2021

Code answers related to "Copy content and add url javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language