This operation is a daily user of some basic operations, but some sites in order to protect copyright (such as novel class, Picture Class), prohibit users to perform these operations, so you can prevent users will be browsing the text, by copying, pasting the way to spread.
Oncopy Event:
Definitions and usage
The Oncopy event is triggered when the user copies the contents of the element.
tip: The Oncopy event also triggers when the user copies elements, such as copy elements.
tip: The Oncopy event is usually used to type= the <input> element of "text."
tip: There are three ways to copy elements and content:
Press CTRL + C
In your browser's Edit menu, choose Copy.
Mail mouse button, select Copy from the context menu.
Browser support
Grammar
In HTML:
<element oncopy= "MyScript" >
In javascript:
Object.oncopy = function () {
//Operation
MyScript
}
In JavaScript, use the AddEventListener () method:
Object.addeventlistener (' Copy ', myScript);
IE8 and earlier IE versions do not support the AddEventListener () method
Onpaste Event:
Definitions and usage
The Onpaste event is triggered when the user pastes text into the element.
Note: Although the HTML element used supports the Onpaste event, it does not actually support all elements, such as the <p> element, unless the contenteditable is set to "true" (see more instances below).
Tip: The Onpaste event is usually used to type= the <input> element of "text."
Tip: There are three ways to paste content in an element:
• Press CTRL + V
• Choose "Paste" from the browser's Edit menu
• Right-click the mouse button to select the "Paste" command in the context menu.
Browser support
<element onpaste= "MyScript" >
In javascript:
Object.onpaste = function () {
//Operation
myScript;
}
JavaScript total, using the AddEventListener () method:
Object.addeventlistener (' paste ', myScript);
Internet Explorer 8 and earlier versions of IE do not support the AddEventListener () method.
Implementation principle:
Performs a copy-and-paste event and returns false in the event.
JavaScript code:
var bodymain = document.getElementById (' Bodymain ');
Prohibit copy
bodymain.oncopy = function () {return
false;
}
Prohibit pasting
bodymain.onpaste = function () {return
false;
}
The above JavaScript is forbidden to copy and paste the implementation code is small series to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.