Javascript DOM HTML Paragraph handle copy event

Introduction

Execute a JavaScript when copying some text of a <p> element:

View in separate window

<!DOCTYPE html>
<html>
<body>

<p oncopy="myFunction()">Try to copy this text</p>

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

</body>
</html>



PreviousNext

Related