javascriptiframeonpaste

How to add onpaste event in frame in IE with javascript?


I want to handle the paste event after clicking right right and select Paste in IE. As an example i did this:

 parent.document.frames["myframe"].document.attachEvent('onclick', function(e) {
      alert("paste");
});

and it works ok. But when I add 'onpaste' instead of 'onclick' it doesn't work. Also I am using javascript and not jquery.

Does anyone have an idea of how this could work?

Thanks


Solution

  • You need to attach the event handler to the <body> element rather than the document because the paste event won't bubble up beyond the <body> element in IE. For example:

    parent.document.frames["myframe"].document.body.attachEvent('onpaste', function(e) {
        alert("paste");
    });