How do I get someone to copy something from my site, go to the "source: myite.com" clipboard?

3

I'd like to make it that when someone copies something from my site, it's automatically added to the content copied from the source, for example:

  

source: myite.com

    
asked by anonymous 07.06.2014 / 20:30

1 answer

2

Use the code below (removed this topic ):

function addLink() {
        var body_element = document.getElementsByTagName("body")[0];
        var selection = window.getSelection();
        var pagelink = '\n\nMai multe Bancuri pe: http://bancuricubarbatisifemei.blogspot.com/\n'; 
        var copytext = selection + pagelink;
        var newdiv = document.createElement('pre');
        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;

JSFiddle

Note: It does not work in Internet Explorer!

    
07.06.2014 / 21:09