473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.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
2 4749
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Aaron Gray | last post by:
<iframe name="iframe" width="100%" height="25%" src="test1.txt"> </iframe> <a href="test1.txt" target="input">one</a> <a href="test2.txt" target="input">two</a> <form name="form1"> <textarea...
0
by: Adrian | last post by:
I want to send some innertext from a textarea on my document to a textarea control on a form within an iframe and then submit the form in the document in the iframe. I managed to get the text...
1
by: Saint's Knight | last post by:
here is code that i use. <html> <head> </head> <body> <form> <input type=checkbox name=source value=1 OnClick="SourceCode(source.checked)">Source <input type=checkbox name=bold...
20
by: effendi | last post by:
I am testting the following code in firefox function fDHTMLPopulateFields(displayValuesArray, displayOrderArray) { var i, currentElement, displayFieldID, currentChild, nDisplayValues =...
1
by: Dave | last post by:
Usual apologies if this is old territory. I'm resizing a bunch of iframes on a page to the height of their contained documents. Some of the contained documents contain IMG tags. On IE this...
1
by: SMichal | last post by:
Hi, is there some posibility how to read inner text from IFRAME on server-side ? I've tested it with innerText and InnerHtml but it doesnt work
12
by: mistral | last post by:
Can anybody tell me how to get source code of page in iframe? (popup window is clickable image). When I right click on this popup border to view source, i see just as follows <html> <head>...
1
by: Sura | last post by:
Hi I have a flash interactive window which has html links and this appears on an html page. This window can be moved with the mouse on the html page. The html page has an iFrame too. When the...
1
by: SunshineInTheRain | last post by:
My project has 3 files, File1 has included master page. file1 consists of iframe1 that load file2. File2 consists of iframe2 that load file3. Javascript used on each file to resize the iframe...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.