Javascript DOM onpaste Event via onpaste function

Introduction

In JavaScript:

object.onpaste = function(){
       myScript};

This example uses the HTML DOM to assign an "onpaste" event to an input element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="text" id="myInput" value="Try to paste something in here" size="40">

<p id="demo"></p>
<script>
document.getElementById("myInput").onpaste = function() {myFunction()};

function myFunction() {/*  w  w  w. j a va2s  . c  o  m*/
  document.getElementById("demo").innerHTML = "You pasted text!";
}
</script>

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



PreviousNext

Related