html tutorial - oncopy Attribute in HTML - html5 - html code - html form



Oncopy attribute in html

Learn html - html tutorial - Oncopy attribute in html - html examples - html programs

  • The oncopy attribute specifies the user duplicates the content of an element.
  • The oncopy attribute is a section of the Event Attributes.
  • There are three actions to copy the content of an element:
    • Press CTRL + C
    • Select "Copy" from the Edit menu in a browser
    • Right click to show the context menu and select "Copy" command.

Syntax for oncopy attribute in HTML:

<input oncopy="script">

Applies To:

Element Attribute
All HTML Elements oncopy

oncopy Attribute Values:

Value HTML 4.0.1 HTML 5 Description
script yes yes The script can run on oncopy.

Sample Coding for oncopy Attribute in HTML:

Tryit<!DOCTYPE html>
<html>
<body>
    <input type="text" value="HTML" oncopy="Wikitechy()">
    <p id="wikitechy"></p>
    <script>
       function Wikitechy() {
           document.getElementById("wikitechy").innerHTML = "Copied the text!"
           }
    </script>
</body>
</html>

Code Explanation for oncopy Attribute in HTML:

oncopy Attribute Code Explanation

  1. <input> tag defines an input field where the user can enter input data.
  2. value attribute defines the value of the HTML element.
  3. Oncopy attribute defines when the user copied the element.
  4. id attribute defines an individual id for an HTML element. The value of Id is wikitechy.
  5. function Wikitechy() is a JavaScript function (block of code), which is created to perform this specific task.
  6. <document.getElementById("wikitechy").innerHTML="Copied the text!">
  7. document.getElementById gives the element which has the ID attribute with the defined value(Here Id value is wikitechy).innerHTML returns the content of an element.

Output for oncopy Attribute in HTML:

oncopy Attribute Output

  1. Here we see the output, the text HTML is displayed when I click the HTML.
oncopy Attribute Output
  1. When I Press CTRL + C The text HTML has been copied.
  2. After coping the text, the content Copied the text! has been displayed.

Browser Support for oncopy Attribute in HTML:

Yes Yes Yes Yes Yes

Tips and Notes

  • The oncopy attribute is mainly applied on <input> elements with type="text"
  • The oncopy attribute cannot work as normal in some web browsers through trying to copy an image.

Related Searches to oncopy attribute in html