4
I would like to know how to inject content into text copied from the page. When I copied a text from a website, it came along with an institutional text and the link from the website. You can see this happening on this website.
4
I would like to know how to inject content into text copied from the page. When I copied a text from a website, it came along with an institutional text and the link from the website. You can see this happening on this website.
3
To do this you need to add an Event Handler to the event copy
.
Inside that Handler you have to fetch the already selected text and then add the new part.
Example:
function addLink(e) {
e.preventDefault();
var copyright = ' - Ler mais aqui: www.google.com';
var novoTexto = copytext = window.getSelection() + copyright;
(window.clipboardData ? window : event).clipboardData.setData('Text', copytext);
}
window.addEventListener('copy', addLink);
In some browsers the clipboardData
is a property of event
, in IE is a property of window
, hence the test window.clipboardData ? window : event
Browser other questions tagged javascript html
You are not signed in. Login or sign up in order to post.
Our Perfect thank you so much
– Rafael Carvalho
There is a great news portal here in Brazil that does this, replacing the copied text with a notice + link to the post. It’s extremely annoying, especially when you just want to copy a sentence.
– bfavaretto
Sergio, how do I run this example in Firefox? It worked on Chrome and IE here.
– Renan Gomes
This is very good to protect content
– Kaizonaro