我希望防止用户进行以下操作:
- 从第一个文本框复制并粘贴到第二个文本框
- 使用右键菜单从第一个文本框复制并粘贴到第二个文本框。
<html>
<head runat="server">
<title>Confirm email page</title>
<script type="text/javascript" language="javascript">
function DisableRightClick(event) {
//For mouse right click
if (event.button == 2) {
}
}
function DisableCtrlKey(e) {
var code = (document.all) ? event.keyCode : e.which;
// look for CTRL key press
if (parseInt(code) == 17) {
window.event.returnValue = false;
}
}
</script>
</head>
<body style="font-family: Verdana; font-size: 1em">
<form id="form1" runat="server">
<div>
<h1>Confirm Email</h1>
<asp:Label ID="Label2" runat="server" Text="Enter Email Address: "></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" oncopy="return false" onMouseDown="DisableRightClick(event)" ></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Confirm Email Address: "></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" onKeyDown="return DisableCtrlKey(event)"></asp:TextBox><br />
</div>
</form>
</body>
</html>
搞定了!!!
<div>
<h1>Copy Paste Preventer!!!</h1>
<asp:Label ID="Label1" runat="server" Text="Enter Username: "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Enter Email Address: "></asp:Label>
<asp:TextBox ID="email" runat="server" oncopy="return false" onpaste="return false" oncut="return false" oncontextmenu="forms[0].elements[0].value++; return false"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Confirm Email Address: "></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" oncopy="return false" onpaste="return false" oncut="return false" oncontextmenu="forms[0].elements[0].value++; return false"> </asp:TextBox><br />
</div>