views:

101

answers:

3

I'm writing a simple editor in an iframe, but having trouble registering the "oninput" event to detect when the user modifies the text field such as pasting in data etc.

    var txtArea =
    document.getElementById('txtArea'); 
    txtArea.contentWindow.document.designMode="on";
    txtArea.contentWindow.document.open();
    txtArea.contentWindow.document.write("<head><style
    type='text/css'>body{font-size:13px;}</style></head><body>"+data.document+"</body>");
    txtArea.contentWindow.document.close();


    $([txtArea.contentWindow.document]).bind("click",
    updateCaretPosMouse); //fires  
    $([txtArea.contentWindow.document]).bind("keyup",
    updateCaretPosKeyboard); //fires  
    $([txtArea.contentWindow.document]).bind("input",
    textChanged); //doesn't fire

If I create a plain old textarea element, and add the "input" event to this, then it works. Do 'input" events not work with iframe text areas?

+1  A: 

oninput is not a official DOM event, it seems to be a Mozilla specific extension (source). Won't keyup do the trick?

Pekka
Nope, I need to detect paste events.
teehoo
This event seems to be new in the HTML5 specification, but Firefox and Chome already support it.http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#common-event-behaviors
teehoo
@teehoo it's well possible that IE8 doesn't (and pretty sure that IE6 and IE7 don't). But to detect paste events, I remember there has been some excellent discussion on that here on SO. I can't do the research right now (need to get back to work) but a search for "detect paste javascript" might do the trick.
Pekka
@Pekka, I found an excellent resource here:http://www.greywyvern.com/?post=282Yes it is possible to work for IE as well using the "propertychange" event. Im focused making it work for FF/Chrome first inside an iframe for now.
teehoo
@teehoo cheers, good to know!
Pekka
A: 

Found out that it isn't possible as of March 03, 2010

http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-March/025402.html

teehoo
A: 

Try using the change event?

Delan Azabani