From: Garrett Smith on
Dr J R Stockton wrote:
> In comp.lang.javascript message <1486365.uhbGJ8BuQJ(a)PointedEars.de>,
> Thu, 29 Oct 2009 19:50:30, Thomas 'PointedEars' Lahn
> <PointedEars(a)web.de> posted:
>> Dr J R Stockton wrote:
>>
>>> Thomas 'PointedEars' Lahn posted:
>>>> Dr J R Stockton wrote:
>>>>> Thomas 'PointedEars' Lahn posted:
>>>>>> Dr J R Stockton wrote:

[snip]

>>>>> It's still annoying that one major browser lacks what others have (even
>>>>> if out of fashion), especially if the functionality is present.
>>>> Which browser would that be?
>>> With a little more - with any - humility and/or common sense, you would
>>> read what you quote both before and after composing a reply. The answer
>>> to that question is plainly visible above, currently at the >>>> level.
>> I have asked before because that implication of yours would be incorrect.
>> Firefox/Gecko does not lack what others have; IE/MSHTML does lack it. While
>> probably not in number of installations, `textContent' is the standards-
>> compliant approach which is supported by more current layout engines than
>> `innerText' is or is going to be.
>
> Firefox apparently lacks what the most-used browser (MSIE), and three
> other major PC browsers, have - innerText of iframe content.
>

The innerText property is a property of an Element. It is read/write
on most, but read only on a few elements.

<URL: http://msdn.microsoft.com/en-us/library/ms533899(VS.85).aspx >

Explains. You can disregard the garbage code by MSFT, which relies on
global scope pollution (element ID becomes globally accessible
property).

The DOM 3 Node textContent property:
http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent

Includes nodeValue when accessed from a CDATASection Node or Comment
Node (I haven't found need for that yet).

> It is of course also a pity that IE lacks textContent - however, it is
> unreasonable to expect (except in Nelson's context) Microsoft to heed
> international standards.
>
MSFT decided not to implement textContent in IE8, for undisclosed
reasons.

https://connect.microsoft.com/IE/feedback/ViewFeedback.aspx?FeedbackID=334438
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Garrett Smith on
Dr J R Stockton wrote:
> In comp.lang.javascript message <hccj1f$6u8$1(a)news.eternal-
> september.org>, Thu, 29 Oct 2009 10:22:40, Garrett Smith
> <dhtmlkitchen(a)gmail.com> posted:
>> Is this the issue I evaded?
>>
>> As I stated, textContent is not related to the frame; stating
>> otherwise,
>> as the proposal for section (9.2) "9.2 How do I access a frame's
>> content?" would be misleading (counterproductive to FAQ goals).
>
>
> If a user's browser shows an iframe element (called Fram), into which a
> typical Web page has been loaded (e.g. by Fram.src=WebPage.htm), the
> user sees something matching the meaning of the word "frame" on the OED;
> and it contains visible material, some of which matches "text" in the
> OED. The frame therefore contains text, and it is reasonable to ask
> "How do I access a frame's content?", and therefore to have that as a
> FAQ section Subject.
>
> Text, in the OED sense, is commonly an important part of a frame's
> content, and so the answer should include how to read it. The fact that
> the frame element does not contain directly a method or property that
> directly yields the text is irrelevant.
>

The "content" is part of the document. That "content" would be something
in that document. Once a reference to the document is obtained, the next
step is to get the content of that document. Possibly as:

fdoc,forms[0].elements["secret"].value;
fdoc.title;
fdoc.getElementById("pwd").value;
// one of:
fdoc.documentElement.textContent;
fdoc.documentElement.innerText;

fdoc.getElementsByTagName("script")[0].innerHTML;

> For the question, the answer should address accessing the "JavaScript"
> content AND the "HTML" content AND the "style" content.
>

Those things are more closely related to a Document. They would belong
under DOM and Forms. For example:

How can I read the text of an element?

> Since all that is easy to do once one knows how, much of the answer can
> readily be given as a series of examples with a little comment : for the
> frame Fram -
>
> COD = Fram.contentDocument
> // Text :
> BOD = COD.body
> TXT = BOD.textContent || BOD.innerText // latter is needed for MSIE
> // HTML :
> HTM = BOD.innerHTML // ??
> // Accoutrements :
> ANK = COD.anchors ; LNK = COD.links ; // etc.
> // JavaScript :
> COW = Fram.contentWindow
> VAR = COW.moo // Fram's JavaScript's var moo
>
> Those are probably about right, but not directly tested; and a couple of
> DOM methods could be shown.
>
Looks about right.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: VK on
Dr J R Stockton wrote:
> >> >> In effect, I want to read the file, HTML or TXT, as it exists on disc.

VK wrote:
> >> >You cannot do it for the reason explained at
> >> >http://groups.google.com/group/comp.lang.javascript/msg/d9f3f6724bada573

Dr J R Stockton wrote:
> >> Unconvincing, because I *am* doing it,

VK wrote:
> >You don't, it is your delusion.
> >I don't know how and why are you doing it, but it was stated that "I
> >want to read the file, HTML or TXT, as it exists on disc." As long as
> >you are not using AJAX calls - and you don't - you are not able and
> >you are not reading any files "HTML or TXT, as it exists on disc" -
> >however wide the definition "as it exists on disc" would be taken.

Dr J R Stockton wrote:
> Give or take irrelevant questions of character coding and newline
> representation, I have been getting, by using innerHTML and by using
> innerText, a string which agrees visually with the content of a TXT file
> on disc, as would be shown by Notepad.

It should be expected in many (but not all) situations.
Contrary to the popular believe, browsers are *not* able to open text
or graphics files. What they are able to - as part of their extended
functionality - is to recognize some file types other than HTML and to
wrap them on the fly into predefined HTML templates so to display them
in the browser window. In the particular for text/plain files they are
using template
<HTML>
<HEAD></HEAD>
<BODY>
<PRE> text file content goes here </PRE>
</BODY>
</HTML>
with the exact tags' case (upper or lower) being browser dependent.
This way the text you "see" is in effect the content of a single <pre>
element necessarily altered from the "as it is on disc" to be placed
into this tag. For instance all less-than and greater-than signs will
be converted to the corresponding named HTML entities. The fact that
you were getting so far "by using innerHTML ..., a string which agrees
visually with the content of a TXT file" suggests that so far you were
lucky but not having any problematic characters in your .txt files,
otherwise see my post about NE (named entities) and NCR (numeric
character references) in HTML:
http://groups.google.com/group/comp.lang.javascript/msg/7a7cb7a5ca4ad387

> I still WANT to read a HTML file correspondingly, seeing the source
> lines as per Notepad; but I don't really NEED to, since what I can get
> suffices for that part of the desired work that is NECESSARY.

The answer remains the same: in order to do so reliably and "as it is
on disk" and not as preprogrammed by this or that browser team, you
have to use XHR (aka AJAX, aka Ajax) and its responseText property
content. Any (i)frames are useless for the task and I hope I made it
clear why. It also solves your reading access synchronization problem,
because with XHR you will be prompted when the content is available or
prompted for the file access error.

VK wrote:
> >As much as I can understand you request, you want to get the textual
> >data from the loaded document in full and without omission which is
> >doable but it is a completely different task.

Dr J R Stockton wrote:
> Yes, that is what I still WANT.  But it is more than, in the case of an
> HTML page, I really NEED.  Therefore progress is being made.

The realization of the actual need and a proper description of this
need is a prerequisite step toward the satisfaction of the need, so
yes, an important progress is being made :)
The satisfaction way is already given a bit above.

> Associated query : I have read a TXT file from disc, getting a matching
> string.  It consists of many lines containing words separated by
> punctuation.  They all start with the same sequence of words and
> punctuation (improbably, zero length), but after that there is always
> non-zero length.  No two lines completely agree.  What is the nicest way
> of determining the common part AND obtaining in sequence strings for the
> varying parts?  Think of it as like a representation of a directory
> tree.

This is OT to the discussed FAQ topic but an interesting problem per
se. I am thinking to move it into separate thread or you may do it
yourself. I have a rather close request for ggNoSpam, in order to give
users an ability to adjust the regexp spam filter even with zero
knowledge of regular expressions. The abstract task description would
be:
"Given an array of strings with the minimum 2 and the maximum 1o
elements, find the shortest common word in these strings. If no such
common character sequence found, then try to find the biggest subset
of strings having a common word".

"word" is understood in regexp terms. To avoid "rush answers" with
common words like "a" or "the" articles let's define that the shortest
common word must be no shorter than 4 characters.


P.S. booh!
:)

From: Dr J R Stockton on
In comp.lang.javascript message <hcdshu$ds2$1(a)news.eternal-
september.org>, Thu, 29 Oct 2009 22:11:19, Garrett Smith
<dhtmlkitchen(a)gmail.com> posted:
>
>As long as I have something to say about it, the entry will correctly
>explain how to access the window object of the IFRAME.
>

You are supposed, as FAQ maintainer, to be sustaining something useful
to the ordinary questioners, especially those who are not full-time
professional JavaScript programmers.

However, you appear entirely unable to understand their positions and
points of view. FAQ maintaining is a task for the sympathetic
communicator; not for the nerd.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
From: Dr J R Stockton on
In comp.lang.javascript message <hcg0mb$cip$1(a)news.eternal-
september.org>, Fri, 30 Oct 2009 16:34:17, Garrett Smith
<dhtmlkitchen(a)gmail.com> posted:
>Dr J R Stockton wrote:

>> Firefox apparently lacks what the most-used browser (MSIE), and
>>three
>> other major PC browsers, have - innerText of iframe content.
>>
>
>The innerText property is a property of an Element. It is read/write
>on most, but read only on a few elements.
> ...

You miss the point, and write irrelevancies. In the context of my
linxchek.htm function ReadDirectoryFile :-

IE works with innerText, but not with textContent.
FF works with textContent, but not with innerText.
Opera, Safari, and Chrome work with either.

It is a pity, and unexpected, that Firefox differs from IE and three
other well-known browsers.

It is a pity, but not unexpected, that IE differs from four other well-
known browsers.

And that is entirely independent of the standards, the mechanism, and
the reasons if any.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)