My requirement: When user copy some content from my web page, with text some HTML tags and carriage retun also gets copied. I need to modify the copied cont
The currently accepted answer is overly complicated, and causes weird behavior where a user's selection is removed after copy.
Here is a much simpler solution:
document.addEventListener('copy', function(e){
var text = window.getSelection().toString().replace(/[\n\r]+/g, '');
e.clipboardData.setData('text/plain', text);
e.preventDefault();
});