How to make so that when a person copies something from my site, go along to the clipboard "source: meusite.com"?

Asked

Viewed 94 times

3

I would like to make that when someone copies something from my site, automatically be added to the copied content the source, for example:

source: meusite.com

  • 2

    http://www.scriptbrasil.com.br/forum/topic/113753-copiar-para-area-de-transferencia/

1 answer

2


Use the code below (removed of 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: Does not work in Internet Explorer!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.