revision:
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.
<element oncopy="script">
script: the script to be run on oncopy
<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>
<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>