HTML DOM Clipboard event

王林
Release: 2023-09-23 16:13:01
forward
949 people have browsed it

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.

Properties

The following are the properties of the Clipboard event−

##Properties Description clipboardData Returns an object containing the data affected by the clipboard operation (cut, copy, or paste).
Events

The following are event types belonging to Clipboard events−

Events Description oncopy This event is triggered when the user copies the content of an element. Oncut This event is triggered when the user cuts the content of the element. onpaste This event is triggered when the user pastes some content in the element.
Syntax

The following is the syntax of clipboard event −

var clipboardEvent = new ClipboardEvent(type,[options]);
Copy after login

Here, type can be 'cut', 'copy' or 'Paste', the second argument is optional. The second parameter contains ClipboardData, dataType, and data.

Example

Let's look at an example of one of the Clipboard event oncopy -

   

Copy after login

Output

This will produce the following output−

HTML DOM Clipboard事件

When copying the text in TEXTBOX −

HTML DOM Clipboard事件

In the above example −

we create a type An 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

Copy after login

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!" }
Copy after login

The above is the detailed content of HTML DOM Clipboard event. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!