HTML - attributes - oncopy

revision:


Content

"oncopy" attribute : when content is copied. syntax some examples


"oncopy" attribute : when content is copied.

top

The oncopy attribute fires when the user copies the content of an element. The attribute also fires when the user copies an element - for example an image - created with the <img> element.
Supported HTML tags: all HTML elements.
Tip: the oncopy attribute is mostly used on <input> elements with type="text".

There are three ways to copy an element/the content of an element: 1/ press CTRL + C; 2/ select "Copy" from the edit menu in the browser; 3/ right click to display the context menu and select the "Copy" command.


syntax

top

<element oncopy="script">

script: the script to be run on oncopy


some examples

top

codes:
                    <input style="margin-left:3vw;" type="text" oncopy="myCopy()" value="Try to copy this text">
                    <p class="spec" id="demo"></p>
                    <script>
                        function myCopy() {
                        document.getElementById("demo").innerHTML = "You copied the text!"
                        }
                    </script>
                

codes:
                    <input style="margin-left:3vw;" type="text" oncopy="myCop()" value="GeeksForGeeks">
                    <p class="spec" id="sudo"></p>
                    <script>
                        function myCop() {
                            document.getElementById("sudo").innerHTML = "Copied box content"
                        }
                    </script>