js屏蔽浏览器右键菜单,粘贴,复制,剪切,选中

js代码制作屏蔽浏览器右键菜单,屏蔽浏览器粘贴,屏蔽浏览器复制,屏蔽浏览器剪切,屏蔽浏览器选中,不会屏蔽搜索引擎蜘蛛抓取页面,不影响seo优化。可以设置网页内容代码不被用户随意下载等。

方法一:示例代码:

<SCRIPT type="text/javascript">

//屏蔽右键菜单

document.oncontextmenu = function (event){

if(window.event){

event = window.event;

}try{

var the = event.srcElement;

if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){

return false;

}

return true;

}catch (e){

return false;

}

}

 

//屏蔽粘贴

document.onpaste = function (event){

if(window.event){

event = window.event;

}try{

var the = event.srcElement;

if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){

return false;

}

return true;

}catch (e){

return false;

}

}

 

//屏蔽复制

document.oncopy = function (event){

if(window.event){

event = window.event;

}try{

var the = event.srcElement;

if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){

return false;

}

return true;

}catch (e){

return false;

}

}

 

//屏蔽剪切

document.oncut = function (event){

if(window.event){

event = window.event;

}try{

var the = event.srcElement;

if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){

return false;

}

return true;

}catch (e){

return false;

}

}

 

//屏蔽选中

document.onselectstart = function (event){

if(window.event){

event = window.event;

}try{

var the = event.srcElement;

if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){

return false;

}

return true;

} catch (e) {

return false;

}

}

</SCRIPT>

 

方法二:示例代码

在页面的body内或者HEAD内增加以下代码来屏蔽JS错误。
<script language='javascript'> 
function resumeerror() {return true;} 
window.οnerrοr=resumeerror; 
</script>

在页面的body内或者HEAD内增加以下代码来屏蔽右键部分功能。
<script type="text/javascript">
document.body.οncοntextmenu=function(){return false;};
document.body.οndragstart=function(){return false;};
document.body.onselectstart=function(){return false;};
document.body.onbeforecopy=function(){return false;};
document.body.οnselect=function(){document.selection.empty();};
document.body.οncοpy=function(){document.selection.empty();};
</script>
在页面的BODY内增加以下代码来防止页面另存,当有人另存页面时就会一直卡在下载的步骤而无法保存,不过这个仅对IE有效,使用opera时一样可以另存。
<noscript><iframe scr="*.htm"></iframe></noscript>

 

方法三:

看代码吧!在body标签中添加如下代码,就能禁止想要的功能。

禁止鼠标右键:οncοntextmenu="return false";

禁止选择:onselectstart="return false";

禁止拖放:οndragstart="return false";

禁止拷贝:οncοpy=document.selection.empty() 。

禁止保存:<noscript><iframe src="*.htm"></iframe></noscript>,放在head里面。

禁止粘贴:<input type=text οnpaste="return false">

关闭输入法:<input style="ime-mode:disabled">

屏蔽打印: <style>@media print{* {display:none}} </style>

转载于:https://my.oschina.net/jimiao/blog/751680

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值