单的JS禁止页面右键菜单--避免网站信息被盗用
<BODY oncontextmenu="return false" onselectstart="return false"
ondragstart="return false" onbeforecopy="return false" oncopy=document.selection.empty() onselect=document.selection.empty()>
-----------------------------------------------
防止复制的js
-----------------------------------------------
下面是防止右键的js:
<!--
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu() {
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e) {
if (window.Event){
if (e.which == 2 || e.which == 3)
return false;
}else{
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>
<title>CSS禁止选择和复制</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
<style>
body{
-moz-user-select:none;
hutia:expression(this.onselectstart=function(){return(false)});
}
</style>
</head>
<body>
这里是网页内容,试试您能不能复制?
</body>
</html>
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 id="form1" runat="server">
<div>
<input id="txt1" type="text" value="Hello World!" onclick="getTxtSelect(event)"/>
<input type="button" value="复制文本框中的值" onclick="SetCopyContent();" />
<input id="txtContent" value="输入搜索条件" style="color:Aqua" onclick="clearTxtByInput();" onblur="FillTxtByInput();" />
<p>content</p>
</div>
</form>
</body>
</html>
新闻热点
疑难解答