|
|
The HTML
oncopy event attribute triggers when a user copies the content of an HTML element or the element itself. This event is part of the HTML DOM (Document Object Model) events and allows for the execution of a script, typically JavaScript, when a copy operation occurs. |
<input type="text" oncopy="myFunction()" value="Try to copy this text">
The oncopy attribute fires when the user copies the content of an element.
Tip: The oncopy attribute also fires when the user copies an element, for example, an image, created with the <img> element.
Tip: The oncopy attribute is mostly used on <input> elements with type="text".
Tip: There are three ways to copy an element/the content of an element:
Note: The oncopy attribute may not work as expected in some browsers when trying to copy an image (See "More Examples" below).
<element oncopy="script">
| Value | Description |
|---|---|
| script | The script to be run on oncopy |
| Supported HTML tags: | ALL HTML elements |
|---|
Try to copy this text.
<!DOCTYPE html>
<html>
<body>
<input type="text" oncopy="myFunction()" value="Try to copy this text">
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You copied text!"
}
</script>
</body>
</html>
Try to copy this text.
<p oncopy="myFunction()">Try to copy this text</p>
Try to copy the image below (Right click on the image and select "Copy Image").
Note: This example may not work as expected in some browsers.
<img src="https://horje.com/avatar.png" oncopy="myFunction()">
| html event attributes |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Clipboard Events Attribute |
Uploaded by: | Admin |
Read Articlehttps://develop.horje.com/learn/1434/reference