Home > Article > Web Front-end > HTML DOM Clipboard event
HTML DOM Clipboard event is used to provide information about clipboard modifications. Events can be cut, copy and paste. Clipboard events can be used to make your website more accessible by providing users with information about how the clipboard has been modified.
The following are the properties of the Clipboard event−
Description | |
---|---|
Returns an object containing the data affected by the clipboard operation (cut, copy, or paste). |
Description | |
---|---|
This event is triggered when the user copies the content of an element. | |
This event is triggered when the user cuts the content of the element. | |
This event is triggered when the user pastes some content in the element. |
var clipboardEvent = new ClipboardEvent(type,[options]);Here, type can be 'cut', 'copy' or 'Paste', the second argument is optional. The second parameter contains ClipboardData, dataType, and data. ExampleLet's look at an example of one of the Clipboard event oncopy -
<!DOCTYPE html> <html> <body> <form> <label> TEXTBOX <input type="text" oncopy="CopyText()" value="Copy this text"> </label> </form> <p id="Sample"></p> <script> function CopyText() { document.getElementById("Sample").innerHTML = "The text has been copied by you!" } </script> </body> </html>OutputThis will produce the following output− When copying the text in TEXTBOX − In the above example − we create a type An d5fd7aea971a85678ba271703566ebfd element for text. It has a tag TEXTBOX assigned to it and already contains some text for the user to select. After the user copies the text, the CopyText() method will be executed. The
<label> TEXTBOX <input type="text" oncopy="CopyText()" value="Copy this text">CopyText() method gets the
element using the getElementById() method on the document and displays "You have copied the text!" inside the paragraph.
function CopyText() { document.getElementById("Sample").innerHTML = "The text has been copied by you!" }
The above is the detailed content of HTML DOM Clipboard event. For more information, please follow other related articles on the PHP Chinese website!