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>

相關文章
相關標籤/搜索