HTML oncopy attribute

HTML oncopy attribute: In this attribute triggers when users copy the content in the element. This attribute accepts a single value script to run. 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.

HTML oncopy attribute

This attribute is a part of all the elements in the HTML.

Syntax: <element oncopy = “script”>

Browser compatibility

This  attribute supports different types of browsers as follows

  • Chrome
  • Mozilla
  • InternetExplorer
  • Safari
  • Opera

Example:

<!DOCTYPE html> 
<html> 
    <head> 
        <title>oncopy attribute</title> 
        <style> 
            body { 
                text-align:center; 
            } 
            h1 { 
                color:green; 
            } 
        </style> 
    </head> 
    <body> 
        <h1>Freshersnow</h1> 
        <h2>oncopy attribute</h2> 
        <input type="text" oncopy="Freshersnow()" value="Freshersnow"> 
        <p id="sudo"></p> 
        <script> 
            function Freshersnow() { 
                document.getElementById("sudo").innerHTML = "Copied box content" 
            } 
        </script> 
    </body> 
</html>            

Output:

html oncopy attribute