Safari, Chrome, Firefox and Internet Explorer support the event onpaste(not sure about Opera). Lock the event onpasteand you can catch it whenever something is inserted.
Writing this is simple enough. Add an event handler to your input using html:<input type="text" id="myinput" onpaste="handlePaste(event);">
or JavaScript DOM:
var myInput = document.getElementById("myInput");
if ("onpaste" in myInput)
{
myInput.onpaste = function (e)
{
var event = e || window.event;
alert("User pasted");
}
}
else if(document.implementation.hasFeature('MutationEvents','2.0'))
{
}
From what I read, Opera does not support the event onpaste. You can use the event DOMAtrrModified, but it could fire even if the scripts change the value of the input field, so you need to be careful with it. Unfortunately, I am not familiar with mutation events, so I would not want to spoil this answer by writing an example that I would not be sure of.
source
share