Include copyright text when copying from the site

Asked

Viewed 103 times

2

It would be like someone copying a text from my site and, no matter where it sticks, display the text it copied and a copyright message?

I found a lot of content on how to block the copy of the content, that’s not what I need, I don’t have any code related to this, because I don’t know how to do it or if there’s any way to do it.

  • Tip: By own experience, it is no use trying to block your code or text, anyway it is always possible to copy it, or someone will be able to do the same. Copyright is independent of registration but only protects a content in full as seen in the law: http://www.casadoautorbrasileiro.com.br/direito-autoral/nocoes-basicas

  • Putting a text with the Logo Copyright for law is merely illustrative

1 answer

5


Here is the Javascript code that will add extra information in the copied web text. Basically it is to create an invisible DOM element and fill it with copied html code by adding the extra information.

Source

function addLink() {
    //Obtem o texto selecionado e acrescenta as informações extras
    var selection = window.getSelection(),
        pagelink = '<br /><br /> mensagem de direitos autorais: ' + document.location.href,
        copytext = selection + pagelink,
        newdiv = document.createElement('div');

    //esconder a div recém-criada
    newdiv.style.position = 'absolute';
    newdiv.style.left = '-99999px';

    //insere a div, adiciona as informações extras e defina a nova seleção
    document.body.appendChild(newdiv);
    newdiv.innerHTML = copytext;
    selection.selectAllChildren(newdiv);

    window.setTimeout(function () {
        document.body.removeChild(newdiv);
    }, 100);
}

document.addEventListener('copy', addLink);
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam hendrerit orci vel urna tincidunt, id aliquet leo dapibus. Nunc sodales arcu auctor, aliquam augue ut, blandit lorem. Ut eleifend dui in interdum fringilla. Etiam eleifend, sem et varius ornare, massa tellus tincidunt metus, ac ultricies ex diam ac arcu. Pellentesque at scelerisque ex. Quisque lobortis lectus sit amet porttitor dapibus. Nunc eget sagittis enim. Aenean mollis rutrum ante. Etiam lacinia aliquam pellentesque. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
<br>
<textarea placeholder="Cole aqui o texto copiado" rows="12" cols="52"></textarea>

To include page title (document.title) in the extra information:

pagelink = '<br /><br /> &copy; '+document.title+'<br /> mensagem de direitos ..................


You can determine from which length of the selected text should display the extra information. Just add that line in the code

if (("" + selection).length < 30) return;

Complete code:

function addLink() {
    //Obtem o texto selecionado e acrescenta as informações extras
    var selection = window.getSelection();
    //se a seleção é curta não vamos incomodar nossos usuários
      if (("" + selection).length < 30) return;

     var  pagelink = '<br /><br /> mensagem de direitos autorais: ' + document.location.href + ' &copy; ' +document.domain,
        copytext = selection + pagelink,
        newdiv = document.createElement('div');

    //esconder a div recém-criada
    newdiv.style.position = 'absolute';
    newdiv.style.left = '-99999px';

    //insere a div, adiciona as informações extras e defina a nova seleção
    document.body.appendChild(newdiv);
    newdiv.innerHTML = copytext;
    selection.selectAllChildren(newdiv);

    window.setTimeout(function () {
        document.body.removeChild(newdiv);
    }, 100);
}

document.addEventListener('copy', addLink);

Browser other questions tagged

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