Disable copy paste in HTML input fields? [duplicat

2019-01-22 02:26发布

Possible Duplicate:
Disable Copy/Paste into HTML form using Javascript

My bank seem to have disabled copy-paste of username and password.

How is it done? Does it improve security?

1条回答
放荡不羁爱自由
2楼-- · 2019-01-22 03:00

You can disable paste in your input as follows:

html:

<input type="text" value="" id="myInput">

javascript:

window.onload = function() {
 const myInput = document.getElementById('myInput');
 myInput.onpaste = function(e) {
   e.preventDefault();
 }
}

Talking about security, I wouldn't say that this makes any impact. You would usually use client side and well as server-side validation of data submitted by the user.

Hope this helps

查看更多
登录 后发表回答