Execute a script when the content of the element is being copied in HTML?

HTMLWeb DevelopmentFront End Technology

When the user cuts the element’s text, the oncopy attribute triggers in HTML.

Example

You can try to run the following code to implement the oncopy attribute −

<!DOCTYPE html>
<html>
   <body>
      <input type = "text" oncopy="display()" value = "Copy me">
      <h2 id = "test">Try to copy the above text.</h2>
      <script>
         function display() {
            document.getElementById("test").innerHTML = "Your copied text worked!";
         }
      </script>
   </body>
</html>
raja
Published on 14-Mar-2018 12:47:01
Advertisements