js中的屏蔽的使用示例
更新時(shí)間:2013年07月30日 15:52:21 作者:
本文為大家介紹下js中的屏蔽的應(yīng)用;屏蔽網(wǎng)頁(yè)內(nèi)容選中、剪切、復(fù)制及拷屏總之你能想象的應(yīng)該都有,感興趣的朋友可以參考下,希望對(duì)大家學(xué)習(xí)js有所幫助
js屏蔽效果
/** 屏蔽F1幫助 */
window.onhelp = function(){return false;}
/**
*屏蔽 F5、Ctrl+N、Shift+F10、Alt+F4
*如果想要屏蔽其他鍵,則找到對(duì)應(yīng)的 keyCode 再依照此方法即可
*/
document.onkeydown = function(event){
event = window.event || event;
if(event.keyCode==116 || (event.ctrlKey && event.keyCode==78) || (event.shiftKey && event.keyCode==121) || (event.altKey && event.keyCode==115)){
event.keyCode =0;
event.returnvalue = false;
}
}
/** 屏蔽鼠標(biāo)右鍵 */
document.oncontextmenu = function(){return false;}
//或者
document.onmousedown = function(event){
event = window.event || event;
if(document.all && event.button == 2) {
event.returnvalue=false;
}
}
/**
* 屏蔽“后退”功能(<a href="javascript:replaceLocation('http://www.google.com')" mce_href="javascript:replaceLocation('http://www.google.com')">Google</a>)
* @param url 頁(yè)面要轉(zhuǎn)向的URL
*/
function replaceLocation(url){
document.location.replace(url);
}
/** 屏蔽選中網(wǎng)頁(yè)內(nèi)容 */
document.onselectstart=function(){return false;}
/** 屏蔽復(fù)制網(wǎng)頁(yè)內(nèi)容 */
document.body.oncopy = function(){return false;}
/** 屏蔽剪切網(wǎng)頁(yè)內(nèi)容 */
document.body.oncut = function(){return false;}
/** 屏蔽向網(wǎng)頁(yè)粘貼內(nèi)容 */
document.body.onpaste = function(){return false;}
/** 屏蔽拷屏(不停的清空剪貼板) */
window.setInterval('window.clipboardData("Text", "")', 100);
/**
* 屏蔽查看源文件( <body onload=clear()> )
*/
function clear() {
var source=document.body.firstChild.data;
document.open();
document.close();
document.body.innerHTML = source;
}
/**
* 屏蔽js報(bào)錯(cuò)
*/
function KillError()
{
return true;
}
window.onerror=KillError;
復(fù)制代碼 代碼如下:
/** 屏蔽F1幫助 */
window.onhelp = function(){return false;}
/**
*屏蔽 F5、Ctrl+N、Shift+F10、Alt+F4
*如果想要屏蔽其他鍵,則找到對(duì)應(yīng)的 keyCode 再依照此方法即可
*/
document.onkeydown = function(event){
event = window.event || event;
if(event.keyCode==116 || (event.ctrlKey && event.keyCode==78) || (event.shiftKey && event.keyCode==121) || (event.altKey && event.keyCode==115)){
event.keyCode =0;
event.returnvalue = false;
}
}
/** 屏蔽鼠標(biāo)右鍵 */
document.oncontextmenu = function(){return false;}
//或者
document.onmousedown = function(event){
event = window.event || event;
if(document.all && event.button == 2) {
event.returnvalue=false;
}
}
/**
* 屏蔽“后退”功能(<a href="javascript:replaceLocation('http://www.google.com')" mce_href="javascript:replaceLocation('http://www.google.com')">Google</a>)
* @param url 頁(yè)面要轉(zhuǎn)向的URL
*/
function replaceLocation(url){
document.location.replace(url);
}
/** 屏蔽選中網(wǎng)頁(yè)內(nèi)容 */
document.onselectstart=function(){return false;}
/** 屏蔽復(fù)制網(wǎng)頁(yè)內(nèi)容 */
document.body.oncopy = function(){return false;}
/** 屏蔽剪切網(wǎng)頁(yè)內(nèi)容 */
document.body.oncut = function(){return false;}
/** 屏蔽向網(wǎng)頁(yè)粘貼內(nèi)容 */
document.body.onpaste = function(){return false;}
/** 屏蔽拷屏(不停的清空剪貼板) */
window.setInterval('window.clipboardData("Text", "")', 100);
/**
* 屏蔽查看源文件( <body onload=clear()> )
*/
function clear() {
var source=document.body.firstChild.data;
document.open();
document.close();
document.body.innerHTML = source;
}
/**
* 屏蔽js報(bào)錯(cuò)
*/
function KillError()
{
return true;
}
window.onerror=KillError;
相關(guān)文章
JavaScript 復(fù)制對(duì)象與Object.assign方法無(wú)法實(shí)現(xiàn)深復(fù)制
這篇文章主要介紹了JavaScript 復(fù)制對(duì)象與Object.assign方法無(wú)法實(shí)現(xiàn)深復(fù)制,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11
純js實(shí)現(xiàn)動(dòng)態(tài)時(shí)間顯示
這篇文章主要為大家詳細(xì)介紹了純js實(shí)現(xiàn)動(dòng)態(tài)時(shí)間顯示,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
JavaScript定時(shí)器實(shí)現(xiàn)的原理分析
JavaScript中的定時(shí)器大家基本在平時(shí)的開(kāi)發(fā)中都遇見(jiàn)過(guò)吧,但是又有多少人去深入的理解其中的原理呢?本文我們就來(lái)分析一下定時(shí)器的實(shí)現(xiàn)原理、定時(shí)器的妙用、定時(shí)器使用注意事項(xiàng),有興趣的朋友可以看下2016-12-12
window.location不跳轉(zhuǎn)的問(wèn)題解決方法
window.location的跳轉(zhuǎn)失效的情況有沒(méi)有遇到過(guò)啊,這主要是冒泡傳遞影響了,下面有個(gè)不錯(cuò)的解決方法,大家可以參考下2014-04-04
JavaScript裝箱及拆箱boxing及unBoxing用法解析
這篇文章主要介紹了JavaScript裝箱及拆箱boxing及unBoxing用法解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06
深入學(xué)習(xí)JavaScript執(zhí)行上下文
這篇文章主要介紹了深入學(xué)習(xí)JavaScript執(zhí)行上下文,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下,希望對(duì)你的學(xué)習(xí)有所幫助2022-08-08
mint-ui的search組件在鍵盤(pán)顯示搜索按鈕的實(shí)現(xiàn)方法
這篇文章主要介紹了mint-ui的search組件在鍵盤(pán)顯示搜索按鈕的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-10-10
10個(gè)在JavaScript開(kāi)發(fā)中常遇到的BUG
給大家詳細(xì)著整理了在JavaScript開(kāi)發(fā)中大家經(jīng)常遇到的BUG和問(wèn)題,需要的朋友參考學(xué)習(xí)下吧。2017-12-12

