如何在Web浏览器上忽略Control + C(复制)

时间:2012-03-31 10:41:28

标签: javascript html xhtml

我试图在我的网站中忽略 Ctrl-C ,但我卡住了。

<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>

我尝试了这段代码,但只能忽略右键点击。

如何忽略 Ctrl-C

2 个答案:

答案 0 :(得分:2)

看看at this website

但如果有人想复制你的内容,他们可以。它只会使使用起来更加困难和耗时。

关于这个Ctrl-C,您可以添加javascript来阻止它,但它没用,因为用户总是可以禁用javascript。事实上,许多用户会发现拦截右键非常烦人。

如果您正在构建Intranet应用程序,或者您可以为用户提供集成浏览器以查看应用程序,则所有这些都有意义。使用公共HTML,我相信它甚至不值得尝试。一种解决方案是使用闪存或其他插件构建应用程序。这样,您就可以加密发送给客户端的所有内容。

答案 1 :(得分:1)

如果你的身体标签添加了这些事件

<body oncontextmenu="return noMenu();" onkeydown="return noKeys(event);">

然后在<head>部分定义这些功能,您可以在激活上下文菜单(右键单击)或在页面上按下键时执行操作。

<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>