<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%;"
通過設(shè)置body屬性來禁用復(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è)試沒有成功,誰知道原因可以在下面給出評(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; } }
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com