how to detect copy and paste in javascript?

前端 未结 2 684
醉酒成梦
醉酒成梦 2021-02-10 08:37

i have two field one is emailid and another is password in my form. i want to detect that when user reenter the email and password than he should not able to copy the above. he

2条回答
  •  無奈伤痛
    2021-02-10 09:23

    2020 update

    There are copy and paste events you can use to prevent these actions, or to modify the data being copied or pasted. (see the links for browser support)

    Or the longer javascript version:

    const elem = document.getElementById('nopaste');
    
    elem.addEventListener('paste', (event) => {
      event.preventDefault();
    });

提交回复
热议问题