HighDots Forums  

FAQ Topic - How do I access a frame's content? (2009-10-25)

Javascript JavaScript language (comp.lang.javascript)


Discuss FAQ Topic - How do I access a frame's content? (2009-10-25) in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-28-2009 , 07:38 PM






In comp.lang.javascript message <hc85ms$v4c$1 (AT) news (DOT) eternal-
september.org>, Tue, 27 Oct 2009 17:10:48, Garrett Smith
<dhtmlkitchen (AT) gmail (DOT) com> posted:
Quote:
FAQENTRY> FAQ 9.7 : ISTM that there may be another cause, or a
refinement of that one. Firefox 3.0.14 gives me "Permission denied to
get property HTMLDocument.anchors" on approximately the 150th time of
doing what seems to be essentially the same thing

I'm busy with several different edits to the FAQ and have not gotten to
a good stopping point.
Do and release one at a time. Forget those version numbers - just date
it (in ISO 8601).


Quote:
Did you post an example of code that causes the error?
No. It's on the Web, within
<URL:http://www.merlyn.demon.co.uk/linxchek.htm> (about 915 lines) at
current line 346 or 351, early in function ReadDOC() and marked. It is
now known to be connected with trying to load into the frame a page
which is in a subdirectory rather than in the current directory.

The problem is not seen in MSIE8 because it never gets that far; and is
not seen in Opera, Safari & Chrome which are happy and proceed to the
end.

There is now an input control "GoUp" which enables reading subdirectory
pages, default 1 but 0 if Firefox is detected; that for me substantially
alleviates the problem, since most of the work is in the current
directory. Also Chrome is very much faster : Chrome 25s, Firefox 112s.

Now that it is known what causes it, a simpler example can be attempted.

FWIW, In Opera an attempt to load into an iframe
a copy of the current page hangs. Ditto, Self.

Both in XP sp3.

Firefox 3.0.15 is available, also 3.5.4.

3.5.4 does the same.


In the same page : LINXCHEK.HTM will not load LINXCHEK.HTM (i.e. itself)
into its iframe in Firefox & Opera, but it will in Safari & Chrome.
MSIE8 fails earlier. Control "Self" deals with that similarly.

--
(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)

Reply With Quote
  #12  
Old   
VK
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-28-2009 , 08:30 PM






Dr J R Stockton wrote:
Quote:
In effect, I want to read the file, HTML or TXT, as it exists on disc.
VK wrote:
Quote:
You cannot do it for the reason explained at
http://groups.google.com/group/comp.lang.javascript/msg/d9f3f6724bada573
Dr J R Stockton wrote:
Quote:
Unconvincing, because I *am* doing it,
You don't, it is your delusion.

Quote:
to the extent that is essential
for the task. *If you consider under what circumstances what can work,
you should be able to deduce how and why I am doing it.
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.
What are you doing is sending requests to the browser to parse the DOM
tree resulted from the loaded source and to convert the nodes back to
the source using back-conversion rules supplied with the given
browser. The difference can be small, huge or a completely different
document - but never equal to the one that "exists on disc".
To help you to visualize it here a sample file that say exists on disc
as test.html with the textual content
<BODY onLoad="alert(document.documentElement.innerHTML)" >
<P>Lorem ipsum
<P>Dolor sit amet
</BODY>

This very file in Geck becomes (I have Skype add-on installed):

<head>
<script
charset="utf-8"
id="injection_graph_func"
src="chrome://skype_ff_toolbar_win/content/injection_graph_func.js">
</script>
</head>
<body onload="alert(document.documentElement.innerHTML)" >
<p>Lorem ipsum
</p><p>Dolor sit amet
</p></body>

and on IE (using outerHTML instead of innerHTML):

<HTML> <HEAD> </HEAD>
<BODY onload="alert(document.documentElement.innerHTML)" >
<P>Lorem ipsum
<P><p>Dolor sit amet </P> </BODY> </HTML>

If the latter two variants do correspond to your definition of "as it
exists on disc" then I am highly amazed.

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.

Reply With Quote
  #13  
Old   
Garrett Smith
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-28-2009 , 11:18 PM



Thomas 'PointedEars' Lahn wrote:
Quote:
Garrett Smith wrote:

Dr J R Stockton wrote:
Thomas 'PointedEars' Lahn posted:
[...]

Quote:
iframe.contentDocument.body.textContent

then. I remember to have posted that explanation before, but the FAQ
had not been updated for some reason.
The innerText/textContent is not related to the frame; its' related to
elements. The frame is a window.

The (i)frame window is represented by a Window instance; the `iframe'
element is not (AISB). Apparently you still need to learn the difference
between element objects and other host objects.

For those who did not notice that I wrote "the frame", and not the
IFRAME element.

Assuming a document with an iframe:

var f = document.getElementsByTagName("iframe")[0];
f.textContent;

- will not get the text content inside the iframe's document.

f.contentDocument.body.textContent

will (where available).

Hopefully that clears up any potential ambiguity.

Quote:
As I've stated before, neither are available in Blackberry9000.

Negligibly small Blackberry market share¹ notwithstanding, that is not
a good reason for ignoring any of the presented solutions at all.
That is, provided it is a frequently asked question to begin with.

Where available, CharacterData is a often a good option. It is widely
supported in modern browsers as:

aTextNode.data
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/

Reply With Quote
  #14  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-29-2009 , 05:51 AM



Garrett Smith wrote:

Quote:
Thomas 'PointedEars' Lahn wrote:
Garrett Smith wrote:
Dr J R Stockton wrote:
Thomas 'PointedEars' Lahn posted:
iframe.contentDocument.body.textContent

then. I remember to have posted that explanation before, but the FAQ
had not been updated for some reason.
The innerText/textContent is not related to the frame; its' related to
elements. The frame is a window.

The (i)frame window is represented by a Window instance; the `iframe'
element is not (AISB). Apparently you still need to learn the difference
between element objects and other host objects.

For those who did not notice that I wrote "the frame", and not the
IFRAME element.

Assuming a document with an iframe:

var f = document.getElementsByTagName("iframe")[0];
f.textContent;

- will not get the text content inside the iframe's document.
Of course not; it will get the (alternative) text content of the element
node. Nobody has ever implied otherwise.

Quote:
f.contentDocument.body.textContent

will (where available).

Hopefully that clears up any potential ambiguity.
Your evading the issue is unsuccessful. Just to remind you: Your
justification for not adding this to the FAQ was that `textContent'
"is not related to the frame", which is ridiculous.

Quote:
As I've stated before, neither are available in Blackberry9000.

Negligibly small Blackberry market share¹ notwithstanding, that is not
a good reason for ignoring any of the presented solutions at all.
That is, provided it is a frequently asked question to begin with.

Where available, CharacterData is a often a good option. It is widely
supported in modern browsers as:

aTextNode.data
s/option/alternative/

Whether it is a good alternative remains to be seen because `data' accesses
only the data of *one* text node at a time, while `textContent' accesses
*all* children text nodes of an element at once.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Reply With Quote
  #15  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-29-2009 , 09:42 AM



In comp.lang.javascript message <7144088.2XM6RcZxFs (AT) PointedEars (DOT) de>,
Wed, 28 Oct 2009 21:01:01, Thomas 'PointedEars' Lahn
<PointedEars (AT) web (DOT) de> posted:
Quote:
Dr J R Stockton wrote:

Thomas 'PointedEars' Lahn posted:
Dr J R Stockton wrote:
I want to read as on disc, certainly; but my needs are substantially
satisfied for TXT files by what innerText and innerHTML show, and for
HTML files by what is actually revealed.

It's annoying that Firefox seems to lack innerText of iframe content,

It implements the `textContent' property instead, like any other browser
standards-compliant in that regard. (Discussed here ad nauseam).

I see. Then why did you not suggest that <FAQENTRY> it should be
included in the frame-content section (9.2) of the FAQ?

Because I do not think it is a frequently asked question.
Then why did you not suggest that the section be removed?


Quote:
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.
Matthew 7:7, Luke 11:9.

Those verses, with their nexts, could be put in the FAQ as a
sort of motto - safely, were it not for the TL effect.



Quote:
FAQENTRY> FAQ 9.7 : ISTM that there may be another cause, or a
refinement of that one. Firefox 3.0.14 gives me "Permission denied to
get property HTMLDocument.anchors" on approximately the 150th time of
doing what seems to be essentially the same thing

SOP?
OAF.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Reply With Quote
  #16  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-29-2009 , 09:53 AM



In comp.lang.javascript message <hca8q9$4j1$1 (AT) news (DOT) eternal-
september.org>, Wed, 28 Oct 2009 12:16:06, Garrett Smith
<dhtmlkitchen (AT) gmail (DOT) com> posted:
Quote:
As I explained, the innerText/textContent is not related to the frame;
it is related to elements. An entry on getting frame's
innerText/textContent implies that a frame has a property
innerText/textContent. That would be false.
In a FAQ, answers should be classified according to the nature of the
question, not according to the nature of the answer.

A common reasoning for questioning is that the answer is not where the
questioner thought to look.

In ordinary English, a frame, or at least an iframe, does commonly have
an innerText or textProperty property; but it is kept by one of its
descendants.

Ask the average elderly person whether they have grandchildren.
Commonly the answer will be "Yes"; it will not be "No; but I have
children who have children".

Anyway, the FAQ said "9.2 How do I access a frame's content?", rightly
omitting any reference to the structure within the frame.

--
(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)

Reply With Quote
  #17  
Old   
Garrett Smith
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-29-2009 , 02:22 PM



Thomas 'PointedEars' Lahn wrote:
Quote:
Garrett Smith wrote:

Thomas 'PointedEars' Lahn wrote:
Garrett Smith wrote:
Dr J R Stockton wrote:
Thomas 'PointedEars' Lahn posted:
iframe.contentDocument.body.textContent

then. I remember to have posted that explanation before, but the FAQ
had not been updated for some reason.
The innerText/textContent is not related to the frame; its' related to
elements. The frame is a window.
The (i)frame window is represented by a Window instance; the `iframe'
element is not (AISB). Apparently you still need to learn the difference
between element objects and other host objects.
For those who did not notice that I wrote "the frame", and not the
IFRAME element.

Assuming a document with an iframe:

var f = document.getElementsByTagName("iframe")[0];
f.textContent;

- will not get the text content inside the iframe's document.

Of course not; it will get the (alternative) text content of the element
node. Nobody has ever implied otherwise.

f.contentDocument.body.textContent

will (where available).

Hopefully that clears up any potential ambiguity.

Your evading the issue is unsuccessful. Just to remind you: Your
justification for not adding this to the FAQ was that `textContent'
"is not related to the frame", which is ridiculous.

If you want to make a proposal, then do so. The proposal was:

Quote:
I see. Then why did you not suggest that <FAQENTRY> it should be
included in the frame-content section (9.2) of the FAQ?
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).

This led to misfortunate confusion, and a diverted side-track discussion
of IFRAME element vs frame.

If you want to make a proposal, try a basic solution-based approach:

e.g. observed problem -> possible approaches to fix -> proposal

something like:
The FAQ has/does not mention [x]
Problems related to [x] come up frequently.
[x] should be mentioned in the FAQ
I propose [x] be be added to the FAQ in the following way:
[short suggestion]

It does not have to be super-formal or strictly follow a format. Recent
comments from G Talbot, for example, were very helpful. Those comments
were assertive and to the point; not lame; not whining.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/

Reply With Quote
  #18  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-29-2009 , 02:50 PM



Dr J R Stockton wrote:

Quote:
Thomas 'PointedEars' Lahn posted:
Dr J R Stockton wrote:
Thomas 'PointedEars' Lahn posted:
Dr J R Stockton wrote:
I want to read as on disc, certainly; but my needs are substantially
satisfied for TXT files by what innerText and innerHTML show, and for
HTML files by what is actually revealed.

It's annoying that Firefox seems to lack innerText of iframe content,

It implements the `textContent' property instead, like any other
browser
standards-compliant in that regard. (Discussed here ad nauseam).

I see. Then why did you not suggest that <FAQENTRY> it should be
included in the frame-content section (9.2) of the FAQ?

Because I do not think it is a frequently asked question.

Then why did you not suggest that the section be removed?
Because I was not aware of its existence to date (obviously I never had a
problem that required searching the comp.lang.javascript FAQ for it), and
because I am not absolutely certain that it is not a frequently asked
question. It is just my impression that it is not, but I may have missed
some questions (definitely those posted with standards-violating `From'
header).

Quote:
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.

Quote:
Matthew 7:7, Luke 11:9.

Those verses, with their nexts, could be put in the FAQ as a
sort of motto - safely, were it not for the TL effect.
So much for "humility and/or common sense".

Quote:
FAQENTRY> FAQ 9.7 : ISTM that there may be another cause, or a
refinement of that one. Firefox 3.0.14 gives me "Permission denied to
get property HTMLDocument.anchors" on approximately the 150th time of
doing what seems to be essentially the same thing

SOP?
OAF.
Sorry, I am not familiar with that acronym, and it is not listed on
<http://www.merlyn.demon.co.uk/acronyms.htm#Acro> or in the usual places.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann

Reply With Quote
  #19  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-29-2009 , 03:48 PM



In comp.lang.javascript message <hccj1f$6u8$1 (AT) news (DOT) eternal-
september.org>, Thu, 29 Oct 2009 10:22:40, Garrett Smith
<dhtmlkitchen (AT) gmail (DOT) com> posted:
Quote:
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.

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

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.

--
(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)

Reply With Quote
  #20  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: FAQ Topic - How do I access a frame's content? (2009-10-25) - 10-29-2009 , 03:57 PM



Garrett Smith wrote:

Quote:
Thomas 'PointedEars' Lahn wrote:
Garrett Smith wrote:
Thomas 'PointedEars' Lahn wrote:
Garrett Smith wrote:
Dr J R Stockton wrote:
Thomas 'PointedEars' Lahn posted:
iframe.contentDocument.body.textContent

then. I remember to have posted that explanation before, but the
FAQ had not been updated for some reason.
The innerText/textContent is not related to the frame; its' related to
elements. The frame is a window.
The (i)frame window is represented by a Window instance; the `iframe'
element is not (AISB). Apparently you still need to learn the
difference between element objects and other host objects.
For those who did not notice that I wrote "the frame", and not the
IFRAME element.

Assuming a document with an iframe:

var f = document.getElementsByTagName("iframe")[0];
f.textContent;

- will not get the text content inside the iframe's document.

Of course not; it will get the (alternative) text content of the element
node. Nobody has ever implied otherwise.

f.contentDocument.body.textContent

will (where available).

Hopefully that clears up any potential ambiguity.

Your evading the issue is unsuccessful. Just to remind you: Your
justification for not adding this to the FAQ was that `textContent'
"is not related to the frame", which is ridiculous.

If you want to make a proposal, then do so.
I need to know first if it is a FAQ to begin with. In any case, I have made
the potential proposal already.

Quote:
The proposal was:

| I see. Then why did you not suggest that <FAQENTRY> it should be
| included in the frame-content section (9.2) of the FAQ?

Is this the issue I evaded?
No, the issue that you are evading is that the approach using `textContent'
is a possible and useful answer to this question.

Quote:
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). [...]
No, it would not. `text*Content*' clearly addresses the issue of accessing
a frame's *content*.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.