HTML oncopy Attribute
Syntax
<element oncopy = "script">
Attribute
This attribute accepts a single value script to be run when oncopy call.
Note: There are 3 ways to copy the content of an element:
- Press CTRL + C to copy an element.
- Select “Copy” from the edit menu.
- Right-click to display the context menu and select the “Copy” command
Example 1:
In this example, we will see the implementation of the above event attribute.
HTML
<!DOCTYPE html> < html > < head > < title >oncopy attribute</ title > < style > body { text-align: center; } h1 { color: green; } </ style > </ head > < body > < h1 >w3wiki</ h1 > < h2 >oncopy attribute</ h2 > < input type = "text" oncopy = "Beginner()" value = "w3wiki" > < p id = "sudo" ></ p > < script > function Beginner() { document.getElementById("sudo").innerHTML = "Copied box content" } </ script > </ body > </ html > |
Output:
Example 2:
In this example, we will see the implementation of the above event attribute with another example.
HTML
<!DOCTYPE html> < html > < head > < title >oncopy attribute</ title > < style > body { text-align: center; } h1 { color: green; } </ style > </ head > < body > < h1 >w3wiki</ h1 > < h2 >oncopy attribute</ h2 > < p oncopy = "Beginner()" > w3wiki: A computer science portal for Beginner </ p > < p id = "sudo" ></ p > < script > function Beginner() { document.getElementById("sudo"). innerHTML = "Copied Text" } </ script > </ body > </ html > |
Output:
Supported Browsers
The browser supported by oncopy Event Attribute are listed below:
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 22 and above
- Opera 12.1 and above
- Safari 3 and above
Contact Us