js禁止頁(yè)面復(fù)制功能禁用頁(yè)面右鍵菜單示例代碼
更新時(shí)間:2013年08月29日 17:30:01 作者:
禁止頁(yè)面復(fù)制功能、禁用頁(yè)面右鍵菜單等等在瀏覽網(wǎng)頁(yè)時(shí)想必大家都有遇到過(guò)吧,下面為大家詳細(xì)介紹下使用js是如何實(shí)現(xiàn)的,感興趣的朋友可以參考下
<body oncontextmenu="return false">禁用網(wǎng)頁(yè)右鍵菜單,但是仍然可以使用快捷鍵復(fù)制。
js代碼禁用復(fù)制功能:
<script type="text/javascript">
document.body.onselectstart=document.body.oncontextmenu=function(){ return false;}
</script>
注意這段代碼必須放在body元素后面,放在前面或者放在head里面都不起作用。
補(bǔ)全:document.body.onselectstart 頁(yè)面選中功能。
document.body.oncontextmenu頁(yè)面右鍵菜單。
document.body.ondragstart頁(yè)面內(nèi)容拖拽功能,拖拽是可以實(shí)現(xiàn)復(fù)制的。禁止復(fù)制時(shí)需要將其禁用。
document.body.oncopy頁(yè)面內(nèi)容復(fù)制功能,當(dāng)禁用時(shí),即使你點(diǎn)擊了復(fù)制或使用了快捷鍵但是你剪切板中的內(nèi)容不是你剛復(fù)制的內(nèi)容而是你以前放在剪切板中的內(nèi)容或?yàn)榭铡?
document.body.oncut頁(yè)面內(nèi)容剪切功能,禁用和效果和禁用復(fù)制功能類似。
注意:當(dāng)使用了上述禁用功能后,如果頁(yè)面的某個(gè)角落還可以右鍵或復(fù)制,那是因?yàn)槟愕腷ody沒有覆蓋整個(gè)頁(yè)面,可以在body上添加如下屬性。
leftMargin=0 topMargin=0 style="width: 100%;height: 100%;"
通過(guò)設(shè)置body屬性來(lái)禁用復(fù)制功能代碼如下:
<body oncontextmenu="return false" onselectstart="return false"
ondragstart="return false" oncopy="return false"
oncut="return false;
leftMargin=0
topMargin=0 style="width: 100%;height: 100%;" >
以下代碼是禁用網(wǎng)頁(yè)另存為但是我測(cè)試沒有成功,誰(shuí)知道原因可以在下面給出評(píng)論,謝謝。
<noscript>
<iframe scr="*.htm"></iframe>
</noscript>
</body>
js代碼案例:
//******************** 屏蔽右鍵 ***********************
function click(e) {
if (document.all) {
if (event.button==1||event.button==2||event.button==3) {
oncontextmenu='return false';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
document.oncontextmenu = new Function("return false;")
//*******************************************
document.onkeydown=function(evt){
if(document.selection.createRange().parentElement().type == "file"){
return false;
}
if ((event.keyCode==116)|| //屏蔽 F5 刷新鍵
(event.ctrlKey && event.keyCode==82)){ //Ctrl + R
event.keyCode=0;
event.returnValue=false;
}
if ((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4
return false;
}
}
js代碼禁用復(fù)制功能:
復(fù)制代碼 代碼如下:
<script type="text/javascript">
document.body.onselectstart=document.body.oncontextmenu=function(){ return false;}
</script>
注意這段代碼必須放在body元素后面,放在前面或者放在head里面都不起作用。
補(bǔ)全:document.body.onselectstart 頁(yè)面選中功能。
document.body.oncontextmenu頁(yè)面右鍵菜單。
document.body.ondragstart頁(yè)面內(nèi)容拖拽功能,拖拽是可以實(shí)現(xiàn)復(fù)制的。禁止復(fù)制時(shí)需要將其禁用。
document.body.oncopy頁(yè)面內(nèi)容復(fù)制功能,當(dāng)禁用時(shí),即使你點(diǎn)擊了復(fù)制或使用了快捷鍵但是你剪切板中的內(nèi)容不是你剛復(fù)制的內(nèi)容而是你以前放在剪切板中的內(nèi)容或?yàn)榭铡?
document.body.oncut頁(yè)面內(nèi)容剪切功能,禁用和效果和禁用復(fù)制功能類似。
注意:當(dāng)使用了上述禁用功能后,如果頁(yè)面的某個(gè)角落還可以右鍵或復(fù)制,那是因?yàn)槟愕腷ody沒有覆蓋整個(gè)頁(yè)面,可以在body上添加如下屬性。
leftMargin=0 topMargin=0 style="width: 100%;height: 100%;"
通過(guò)設(shè)置body屬性來(lái)禁用復(fù)制功能代碼如下:
復(fù)制代碼 代碼如下:
<body oncontextmenu="return false" onselectstart="return false"
ondragstart="return false" oncopy="return false"
oncut="return false;
leftMargin=0
topMargin=0 style="width: 100%;height: 100%;" >
以下代碼是禁用網(wǎng)頁(yè)另存為但是我測(cè)試沒有成功,誰(shuí)知道原因可以在下面給出評(píng)論,謝謝。
<noscript>
<iframe scr="*.htm"></iframe>
</noscript>
</body>
js代碼案例:
復(fù)制代碼 代碼如下:
//******************** 屏蔽右鍵 ***********************
function click(e) {
if (document.all) {
if (event.button==1||event.button==2||event.button==3) {
oncontextmenu='return false';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
document.oncontextmenu = new Function("return false;")
//*******************************************
document.onkeydown=function(evt){
if(document.selection.createRange().parentElement().type == "file"){
return false;
}
if ((event.keyCode==116)|| //屏蔽 F5 刷新鍵
(event.ctrlKey && event.keyCode==82)){ //Ctrl + R
event.keyCode=0;
event.returnValue=false;
}
if ((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4
return false;
}
}
您可能感興趣的文章:
- 網(wǎng)頁(yè)源代碼保護(hù)(禁止右鍵、復(fù)制、另存為、查看源文件)
- JS實(shí)現(xiàn)禁止鼠標(biāo)右鍵的功能
- js禁止頁(yè)面刷新禁止用F5鍵刷新禁止右鍵的示例代碼
- firefox(火狐)和ie瀏覽器禁止右鍵和禁止復(fù)制的代碼
- javascript實(shí)現(xiàn)禁止右鍵和F12查看源代碼
- JS禁止瀏覽器右鍵查看元素或按F12審查元素自動(dòng)關(guān)閉頁(yè)面示例代碼
- JavaScript代碼實(shí)現(xiàn)禁止右鍵、禁選擇、禁粘貼、禁shift、禁ctrl、禁alt
- JavaScript鼠標(biāo)禁止右鍵禁止打開控制臺(tái)及鍵盤禁用
相關(guān)文章
JS中Iframe之間傳值及子頁(yè)面與父頁(yè)面應(yīng)用
用iframe做系統(tǒng)框架,相信很多朋友都有這樣的經(jīng)歷吧,接下來(lái)將為你詳細(xì)介紹下JS中Iframe之間傳值應(yīng)用,感興趣的你可以參考下哈,希望可以幫助到你2013-03-03JS數(shù)組操作之增刪改查的簡(jiǎn)單實(shí)現(xiàn)
本篇文章主要介紹了JS數(shù)組操作之增刪改查的簡(jiǎn)單實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08用JavaScript檢查大寫鍵(Caps Lock)是否打開的腳本
用JavaScript檢查大寫鍵(Caps Lock)是否打開的腳本...2007-06-06