Javascript paste
The javascript onpaste event occurs when the user pastes some content in an element(input).
The paste event is supported by all HTML elements, it is not actually possible to paste some content in, for example, an <p> element, UNLESS the element has set content editable to “true”.
Three ways to paste some content:
⦁ Press CTRL + V
⦁ Select “Paste” from the Edit menu.
⦁ Right-click to display the context menu and select the “Paste” option.
Syntax
In HTML:
<element onpaste="myScript">
In JavaScript:
object.onpaste = function(){myScript};
EXAMPLE:
<!DOCTYPE html>
<html>
<body>
<p contenteditable="true" onpaste="myFunction()">Try to paste something inside this paragraph.</p>
<script>
function myFunction() {
alert("You pasted text!");
}
</script>
</body>
</html>
OUTPUT:
![]()