HTML | oncopy Attribute

This attribute fires when the user copied the content present in an element. The oncopy attribute is used with <img>, <input>, <p> etc elements.

Syntax:

<element oncopy = "script">

Attribute: This attribute accept single value script to be run when oncopy call.

Note:There are 3 ways to copy the content of an elements:

  • 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>oncopy attribute</title>
        <style>
            body {
                text-align:center;
            }
            h1 {
                color:green;
            }
        </style>
    </head>
    <body>
        <h1>GeeksForGeeks</h1>
        <h2>oncopy attribute</h2>
        <p oncopy="Geeks()">GeeksforGeeks: A computer science portal for Geeks</p>
        <p id="sudo"></p>
        <script>
            function Geeks() {
                document.getElementById("sudo").innerHTML = "Copied Text"
            }
        </script>
    </body>
</html>                    

chevron_right


Output:

Supported Browsers: The browser supported by oncopy Event Attribute are listed below:

  • Internet Explorer
  • Google Chrome
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.