开发者

Simple iframe editor and oninput event

开发者 https://www.devze.com 2022-12-28 09:37 出处:网络
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.

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("clic开发者_运维技巧k",
    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?


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


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

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


Try using the change event?

0

精彩评论

暂无评论...
验证码 换一张
取 消