JS prohibit page Copy feature disable page right-click menu Sample Code _javascript Tips

Source: Internet
Author: User
<body oncontextmenu= "return false" > Disable the right-click menu of the Web page, but you can still use shortcut keys to copy.
JS code disables the replication feature:
Copy Code code as follows:

<script type= "Text/javascript" >
Document.body.onselectstart=document.body.oncontextmenu=function () {return false;}
</script>

Note that this code must be placed behind the body element, in front or in the head without any effect.
Complement: Document.body.onselectstart page check function.
Document.body.oncontextmenu page Right menu.
Document.body.ondragstart page content drag and drop function, drag can be achieved replication. You need to disable replication when you prohibit it.
Document.body.oncopy page content copy function, when disabled, even if you clicked Copy or use shortcut keys but the contents of your clipboard are not what you have just copied but what you have previously placed in the Clipboard or empty.
Document.body.oncut page Content clipping features, disabling and effects are similar to disabling replication.
Note: When you use the above disabling function, if a corner of the page can also right-click or copy, it is because your body does not cover the entire page, you can add the following properties on the body.
Leftmargin=0 topmargin=0 style= "width:100%;height:100%;"
Disable the Copy function code by setting the Body property as follows:
Copy Code code as follows:

<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%;" >
The following code is to disable the Web page save as but I did not succeed in the test, who knows the reason can give a comment below, thank you.
<noscript>
<iframe scr= "*.htm" ></iframe>
</noscript>
</body>

JS Code case:
Copy Code code as follows:

Shielding right Button ***********************
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) | |//shielding 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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.