Javascript DOM oncopy Event via addEventListener() method

Introduction

In JavaScript, using the addEventListener() method:

object.addEventListener("copy",
       myScript);

This example uses the addEventListener() method to attach a "copy" event to an input element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="text" id="myInput" value="Try to copy this text">
<p id="demo"></p>
<script>
document.getElementById("myInput").addEventListener("copy", myFunction);

function myFunction() {/*from w  w w .jav  a 2 s  . co  m*/
  document.getElementById("demo").innerHTML = "You copied text!";
}
</script>

</body>
</html>
Bubbles: Yes
Cancelable: Yes
Event type: ClipboardEvent
Supported HTML tags: All HTML elements



PreviousNext

Related