Home > Web Front-end > JS Tutorial > js disable page copy function disable page right-click menu sample code_javascript skills

js disable page copy function disable page right-click menu sample code_javascript skills

WBOY
Release: 2016-05-16 17:23:57
Original
1056 people have browsed it

Disables the web page right-click menu, but you can still use shortcut keys to copy.
js code disables the copy function:

Copy code The code is as follows:



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:
Copy code The code 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:

Copy code The code is as follows:
//************************ 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;
}
}

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template