By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,365 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,365 IT Pros & Developers. It's quick & easy.

IFrame innerText FireFox

P: n/a
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[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.

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
de*******@gmail.com wrote:
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[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");


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

--
Rob
Jul 23 '05 #2

P: n/a
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.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.