Modify Clipboard content after copy event: JavaScript, jQuery

前端 未结 4 816
感情败类
感情败类 2020-12-15 12:30

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

4条回答
  •  时光说笑
    2020-12-15 12:51

    There are two things I can find out.

    1. clipboardData object will be in callback object e passed not in window.
    2. the correct syntax for setData is like below.

    For further reference copy Event MDN

    document.addEventListener('copy', function(e) {
      console.log('copied');
      e.clipboardData.setData('text/plain', 'Hello World!');
      e.preventDefault();
    });
    

提交回复
热议问题