IFrame innerText FireFox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • delraydog@gmail.com

    #1

    IFrame innerText FireFox

    I know that innerText is not supported in FireFox and I've found the
    following code fragment which was originally designed in an HTMLElement
    prototype for an innerText getter. I do not however want to use the
    getter approach and want to just get the innerText as follows:

    var childS = iframe.contentW indow.document. body.childNodes ;
    for(var i=0; i<childS.length ; i++)
    {
    if(childS[i].nodeType==1)
    text+= childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
    else
    if(childS[i].nodeType==3)
    text+= childS[i].nodeValue;
    }

    Unfortunately, this does not work... iframe is an instance of an object
    created as follows: iframe=document .createElement( "iframe");

    Any suggestions on how to make this work? I think the answer lies in
    the declaration of childS but I'm not quite sure.

    Cliff.

  • RobG

    #2
    Re: IFrame innerText FireFox

    delraydog@gmail .com wrote:[color=blue]
    > I know that innerText is not supported in FireFox and I've found the
    > following code fragment which was originally designed in an HTMLElement
    > prototype for an innerText getter. I do not however want to use the
    > getter approach and want to just get the innerText as follows:
    >
    > var childS = iframe.contentW indow.document. body.childNodes ;
    > for(var i=0; i<childS.length ; i++)
    > {
    > if(childS[i].nodeType==1)
    > text+= childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
    > else
    > if(childS[i].nodeType==3)
    > text+= childS[i].nodeValue;
    > }
    >
    > Unfortunately, this does not work... iframe is an instance of an object
    > created as follows: iframe=document .createElement( "iframe");[/color]

    Please define 'does not work' - scripts will generally (try to) do
    exactly what you tell them to. Is there an error message, or is the
    result just not what you expected?

    childS should be a collection of the children of the document body
    element - have you tested it to see what it is? Have you tried
    something like:

    for ( var i=0; i<childS.length ; i++) {
    alert(childS[i].nodeName + ': ' + childS[i].innerHTML);
    }

    Just to see what you get?

    In any case, seems you are just after the content of the body, so
    presuming you can get a reference to the body of your iframe and that
    innerHTML is supported, the required functionality of innerText you are
    after can likely be provided by:

    var iframeBody = iframe.contentW indow.document. body;
    var p = iframeBody.inne rHTML.replace(/<br>/gi,'\n');
    p = p.replace(/(<[^>]*?>)/g,'');
    alert(p);



    --
    Rob

    Comment

    • delraydog@gmail.com

      #3
      Re: IFrame innerText FireFox

      The only issue with this approach is that a linefeed character is
      inserted before the text... also, I'm not sure about embedded HTML tags
      in the text.

      Cliff.

      Comment

      Working...