IFrame innerText FireFox

D

delraydog

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.contentWindow.document.body.childNodes;
for(var i=0; i<childS.length; i++)
{
if(childS.nodeType==1)
text+= childS.tagName=="BR" ? '\n' : childS.innerText;
else
if(childS.nodeType==3)
text+= childS.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.
 
R

RobG

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.contentWindow.document.body.childNodes;
for(var i=0; i<childS.length; i++)
{
if(childS.nodeType==1)
text+= childS.tagName=="BR" ? '\n' : childS.innerText;
else
if(childS.nodeType==3)
text+= childS.nodeValue;
}

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


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.nodeName + ': ' + childS.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.contentWindow.document.body;
var p = iframeBody.innerHTML.replace(/<br>/gi,'\n');
p = p.replace(/(<[^>]*?>)/g,'');
alert(p);
 
D

delraydog

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top