【发布时间】:2017-03-25 21:02:04
【问题描述】:
<html>
<head><title>Practice</title>
<script language="javascript" type="text/javascript">
function disableCopy() {
alert("You cannot perform Copy");
return false;
}
function disablePaste() {
alert("You cannot performing Paste");
return false;
}
function disableCut() {
alert("You cannot perform Cut");
return false;
}
function disableContextMenu() {
alert("You cannot perform right click via mouse as well as keyboard");
return false;
}
</script>
</head>
<body>
<textarea rows=10 cols=50 oncopy="return false" onpaste="return false" oncut="return false" oncontextmenu="return false">
Enter Text here......
</textarea>
<br/>
Password<input type="password" oncopy="return disableCopy();" id="pwd" onpaste="return disablePaste();" oncut="return disableCut();" oncontextmenu="return disableContextMenu();"/>
</body>
</html>
朋友们好,我刚开始学习 Javascript,在上面的示例中执行复制、剪切和粘贴密码等操作时,我遇到了密码标签的问题。在这里,我使用了 onCopy、onPaste 和 onCut 事件,通过编写代码所示的 Javascript 函数来禁用剪切、复制和粘贴操作。但是,当我在 Mozilla 浏览器中运行相同的示例时,每个事件函数都会按预期执行警报,但是当我在 Chrome 浏览器或 Internet Explorer 中运行相同的示例时,我没有收到警报。任何人都可以帮我解决这个问题,或者任何人都可以提供一个替代解决方案,以便可以在所有三种浏览器(即 Mozilla、Chrome、Internet Explorer)上测试相同的示例。
提前致谢
【问题讨论】:
-
请记住,用户可以简单地停用 js。所以任何 JS 保护无论如何都不可靠。考虑到这一点:您真的需要这种功能吗?
-
在 newBee 上添加:我总是讨厌程序/网站试图强迫我以某种方式输入我的数据。我讨厌不能使用复制/粘贴。如果可能的话,我以后会避免使用此类网站。
-
不要这样做。真的,真的,不要这样做。如果我无法将密码粘贴到某个字段中,那么我们鼓励我使用简短且易于输入的密码。这意味着密码相对不安全。
-
我完全同意,但如果客户想要,那么客户就会得到。如果他们为此付出代价,那么您就无法真正反驳。
-
借助这个 tut,您可以 - kvcodes.com/2014/03/…
标签: javascript html