HTML event attribute oncopy

The oncopy attribute event is triggered when copying the content of an element.

What's new in HTML5



<element oncopy="script or Javascript function name">

Supported Tags

ALL HTML elements

Browser compatibility

oncopy Yes Yes Yes Yes Yes


<!DOCTYPE html>
<!--   w  w w .j  av a  2  s. co m-->
<p oncopy="myFunction()">Copy me</p>

function myFunction() {
    console.log("You copied text!");


Click to view the demo