SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    iframe event capturing

    hi

    how to capture onkeyup event from an editable iframe in firefox?
    any suggestion appreciated...
    thanx in advance!

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok...
    maybe ill be more clear when posting some code...
    Code:
    var iFrDoc = document.getElementById(arguments[0]).contentWindow.document ||
                     document.getElementById(arguments[0]).contentDocument.document;
    iFrDoc.body.innerHTML = "myText";
    if(!document.all) 
           iFrDoc.designMode = "on";
    else 
           iFrDoc.body.contentEditable = true;
    
    iFrDoc.focus();
    iFrDoc.onkeyup = callBack;
    this piece of code works great in IE...
    but in firefox neither the focus is seted up and the onkeyup event doesnt work?
    any suggestion appreciated...
    thanx in advance...
    Last edited by reminder; Dec 16, 2007 at 02:20.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i found the solution...
    for gecko based browsers the event has to be attached on contentDocument
    hth
    Code:
    var iFrm = document.getElementById(arguments[0]);
    iFrm.contentWindow.document.body.innerHTML = "myText";
    if(iFrm.contentDocument) {
            iFrm.contentDocument.addEventListener("keyup", callBack, false);
            iFrm.contentDocument.designMode = "on";
            iFrm.contentWindow.focus();
    } else {
            iFrm.contentWindow.document.body.attachEvent("onkeyup", callBack);
            iFrm.contentWindow.document.body.contentEditable = true;
            iFrm.contentWindow.document.body.focus();
    }
    note that the focus for gecko must be set to contentWindow...
    regards

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have another question...
    how to set cursor position on editable document at the end of the text?
    i tried to set focus on the documentWindow and select text ranges but its not a textarea so it doesnt work!
    i have working code for IE but not for firefox.
    any suggestion appreciated...
    thanx in advance.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •