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.


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

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