JavaScript禁止页面操作的示例代码(2)

function clearTxtByInput() {
            document.getElementById("txtContent").value = "";
        }

function FillTxtByInput() {
            document.getElementById("txtContent").value = "输入搜索条件";
        }
        //禁用键盘上的某几个键 调用onkeydown="ForbidKeys();"
        function ForbidKeys() {
            var content = window.event.keyCode;
            if (content >= 65 && content <= 68) {
                window.event.returnValue = false;
            } else {
                window.alert(content);
            }
        }

//禁止复制网页内容 <body oncopy="forbidCopy();">
         function forbidCopy() {
            window.event.returnValue = false;
            window.clipboardData.setData("Text", "");
            alert("禁止复制网页内容!");
        }

        //设置复制内容 附加 本网站的URL
        function SetCopyContent() {
            window.event.returnValue = false;
            var content = document.title + "/r/n";
            content += document.getElementById("txt1").value + "/r/n";
            content += "本资源来自 " + this.location.href;
            window.clipboardData.setData('Text', content);
            alert("复制成功,请粘贴到你的QQ/MSN上推荐给你的好友");
        }

//禁止刷新F5 和Ctrl+F5
        function ForbidFreshPage() {

if ((window.event.ctrlKey && window.event.keyCode == 116) || window.event.keyCode == 116) {
               window.event.keyCode = 0;
               window.event.returnValue = false;
           }
        }
        document.onkeydown = ForbidFreshPage;
        //屏蔽JS错误
        function killErrors() {
            return true;
        }
        window.onerror = killErrors;


    </script>
</head>
<body>
    <form runat="server">
    <div>
        <input type="text" value="Hello World!" />
        <input type="button" value="复制文本框中的值"  />
        <input value="输入搜索条件"  onblur="FillTxtByInput();" />
        <p>content</p>

    </div>
    </form>
</body>
</html>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdwdzy.html