Tuesday, October 5, 2010

How to avoid ctrl+c or ctrl+v on a field (javascript)

I've found this code somewhere (I don't remember the website and I
lost the address), and it's very simple and useful:

You can create this function in javascript:

<script language="javascript" type="text/javascript>
function onKeyDown() {
var pressedKey = String.fromCharCode(event.keyCode).toLowerCase()
if (event.ctrlKey && (pressedKey == 'c' || pressedKey == 'v')) {
event.returnValue = false;
}
}
</script>

text tag in a asp.net page
<asp:TextBox ID="txtText" runat="server" Width="80px" MaxLength="10"
onKeyDown="onKeyDown()" ></asp:TextBox>

No comments:

Post a Comment