网页中禁止右键,F12,选中代码,网页选中,另存为,查看,防复制代码等方法

分类:站长 时间:2019-09-02 14:20 浏览:1646
概述
0.禁止按键F12 if(top.location != self.location)top.location=self.location;  function keyboardevent(e){      var 
内容

0.禁止按键F12

<script type="text/javascript">
if(top.location != self.location)top.location=self.location; 
function keyboardevent(e){ 
var ev = e || window.event;//获取event对象     
var obj = ev.target || ev.srcElement;//获取事件源     
//禁 F12
if(ev.keyCode==13 || ev.keyCode==123 || ev.which == 123){
ev.keyCode=0;
return false;     
}   
//禁 ctrl+s 
if(ev.ctrlKey && ev.keyCode==83){
return false;
}
//禁选择input下backspace
if (ev.keyCode == 8) {  
var tagName = obj.nodeName //标签名称  
//如果标签不是input或者textarea则阻止Backspace  
if (tagName != 'INPUT' && tagName != 'TEXTAREA') {  
return stopIt(ev);  
}  
var tagType = obj.type.toUpperCase();//标签类型  
//input标签除了下面几种类型,全部阻止Backspace  
if (tagName == 'INPUT' && (tagType != 'TEXT' && tagType != 'TEXTAREA' && tagType != 'PASSWORD')) {  
return stopIt(ev);  
}  
//input或者textarea输入框如果不可编辑则阻止Backspace  
if ((tagName == 'INPUT' || tagName == 'TEXTAREA') && (obj.readOnly == true || obj.disabled == true)) {  
return stopIt(ev);  
}  
}  
} 
function stopIt (ev) {  
if (ev.preventDefault) {  
//preventDefault()方法阻止元素发生默认的行为  
ev.preventDefault();  
}  
if (ev.returnValue) {  
//IE浏览器下用window.event.returnValue = false;实现阻止元素发生默认的行为  
ev.returnValue = false;  
}  
return false;  
} 
document.onkeypress=keyboardevent;  
document.onkeydown=keyboardevent;  
</script>


1.禁止鼠标左右键

<SCRIPT language=javascript>
<!--
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
18 event.returnValue = false;
19 return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</SCRIPT>


2.禁止鼠标左右键代码/禁止网页选中/禁止另存为/防复制代码

<body oncontextmenu="return false" onselectstart="return false">
<noscript><iframe src="/*.html>";</iframe></noscript>
<script>
function stop(){
return false;
}
document.oncontextmenu=stop;
</script>



3.禁止选中代码

<SCRIPT language=JavaScript>
document.oncontextmenu=new Function("event.returnValue=false;");
document.onselectstart=new Function("event.returnValue=false;");
</SCRIPT>


4.禁止另存为

<noscript>
<iframe src="/*.htm"></iframe>
</noscript>


5.防拷贝/复制代码

<body leftmargin=0 topmargin=0 >




6.禁止选择文本

<script type="text/javascript">
var omitformtags=["input", "textarea", "select"]
omitformtagsomitformtags=omitformtags.join("|")
function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}
function reEnable(){
return true
}
if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
</script>



7.禁止网页另存为

<noscript><iframe src="/*.html>";</iframe></noscript>


8.禁止选择文本

<script type="text/javascript">

var omitformtags=["input", "textarea", "select"]

omitformtagsomitformtags=omitformtags.join("|")

function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}

function reEnable(){
return true
}

if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
</script>


9.禁用右键

<script>
function stop(){
return false;
}
document.oncontextmenu=stop;
</script>


10.真正的鼠标右键屏蔽

<script language="JavaScript">
<!--

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>



反之则需要取消,也是找到以上相关代码取消就可以了。

评论
  • 猎伞底部波浪
  • 猎伞底部波浪
  • 猎伞底部波浪
  • 猎伞底部波浪

我的

足迹

投稿

反馈

客服

猎伞官方客服

客服QQ:104****84 (点击直接对话)

客服电话:400****16(查看完整电话)

客服邮箱:service@liesan.com

管理仅处理交易投诉、举报、帐号、资金等平台使用问题;
商品问题请咨询各商品详情页面中显示的商家客服QQ。

正常模式精简模式

返回顶部