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

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

方法一:示例代码:java

<SCRIPT type="text/javascript">浏览器

//屏蔽右键菜单优化

document.oncontextmenu = function (event){搜索引擎

if(window.event){spa

event = window.event;.net

}try{htm

var the = event.srcElement;索引

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

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.onerror=resumeerror; 
</script>

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

 

方法三:

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

禁止鼠标右键:oncontextmenu="return false";

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

禁止拖放:ondragstart="return false";

禁止拷贝:oncopy=document.selection.empty() 。

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

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

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

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

相关文章
相关标签/搜索