如何在 Web 浏览器上忽略 Control+C(复制)
问题描述:
我试图忽略我网站中的 Ctrl-C 但我卡住了.
I'm trying to ignore Ctrl-C in my website but im stuck.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript">
function whichButton(event)
{
if (event.button==2)//RIGHT CLICK
{
alert("Not Allow Right Click!");
}
}
function noCTRL(e)
{
var code = (document.all) ? event.keyCode:e.which;
var msg = "Sorry, this functionality is disabled.";
if (parseInt(code)==17) //CTRL
{
alert(msg);
window.event.returnValue = false;
}
}
</script>
</head>
<body>
<form method="">
<strong>Not Allow Paste </strong><BR>
<input type="text" value="" onMouseDown="whichButton(event)" onKeyDown="return noCTRL(event)"/>
</form>
</body>
</html>
我试过这段代码,但它只能忽略右键单击.
I tried this code, but it is can only ignore right click.
如何忽略Ctrl-C?
答
如果你的 body 标签添加了这些事件
if your body tag adds these events
<body oncontextmenu="return noMenu();" onkeydown="return noKeys(event);">
然后您在 部分定义这些函数,您可以在上下文菜单被激活(右键单击)或在页面上按下键时执行操作.
and you then define these functions in your <head>
section, you can take action when the context menu is activated (right click) or when keys are pressed on your page.
<script type="text/javascript">
function noMenu()
{
alert("Not Allow Right Click!");
return false;
}
function noKeys(event)
{
if (event == null) event = window.event;
// here you can check event.keyCode
return false;
}
</script>