js onpaste event, prohibit paste

js onpaste event, prohibiting pasting


There is an event onpaste in js that prohibits pasting; it is mainly used in the user filling in information, registration, etc., when the user fills in some very important information, such as mobile phone number, confirmation email, etc., to prevent the user from first Typing mistakes and pasting directly for the second time are also more common. For example, on the registration page of Alipay, the entire form is prohibited from pasting.

The basic usage is to add onpaste=”fnPaste()” to the text box;
<input type="text" name="textfield" onpaste="return false" id="textfield" />  


If you imagine the registration page of Alipay, if the entire form is prohibited from pasting, you can add onpaste=”return false” to the body tag;
<body onpaste="return false" >  


Of course you can also add custom methods:
<input type="text" name="textfield" onpaste="sayHi()" id="textfield" />   
function sayHi(){     
alert("hi");    
}  


One thing worth noting is that Opera does not support onpaste events. IE6-8, Safari, firefox 3 are all supported.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326589789&siteId=291194637