Disables the web page right-click menu, but you can still use shortcut keys to copy.
js code disables the copy function:
Note This code must be placed after the body element. It will not work if placed in front or inside the head.
Complete: document.body.onselectstart page selection function.
Document.body.oncontextmenu page right-click menu.
document.body.ondragstart page content drag and drop function, drag and drop can be copied. It needs to be disabled when copying is prohibited.
document.body.oncopy page content copy function, when disabled, even if you click copy or use shortcut keys, the content in your clipboard is not the content you just copied but the content you previously placed on the clipboard. The contents may be empty.
document.body.oncut page content cutting function, disabling it has the same effect as disabling copying function.
Note: After using the above disabled function, if you can still right-click or copy a corner of the page, it is because your body does not cover the entire page. You can add the following attributes to the body.
leftMargin=0 topMargin=0 style="width: 100%;height: 100%;"
The code to disable the copy function by setting the body attribute is as follows:
ondragstart="return false" oncopy ="return false"
oncut="return false;
leftMargin=0
topMargin=0 style="width: 100%;height: 100%;" >
The following code is a disabled web page Save as but my test failed, who knows the reason can leave a comment below, thank you.
js code example:
//************************ Block right click************ ***********
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)|| //Shield the F5 refresh key
(event.ctrlKey && event.keyCode ==82)){ //Ctrl R
event.keyCode=0;
event.returnValue=false;
}
if ((window.event.altKey)&&(window.event. keyCode==115)){ //Shield Alt F4
return false;
}
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn