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
  #1  
Old   
FAQ server
 
Posts: n/a

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






-----------------------------------------------------------------------
FAQ Topic - How do I access a frame's content?
-----------------------------------------------------------------------

To reference another frame on the _same domain_:

A frame's content window can be found from the ` frames ` collection.

Example:

var fwin;
fwin = self.frames[0]; // or:
fwin = self.frames["iframeName"];

or from the ` IFRAME ` or ` FRAME ` element:

var iframeEl = document.getElementById("myFrame");
var fwin = iframeEl.contentWindow;

An identifier ` moomin ` in the the iframe's content window,
is accessed as ` fwin.moomin `.

To communicate between frames on _different_ domains:

Where supported, (IE8, Firefox 3, Opera 9, Safari 4), use
` window.postMessage( message[, port], otherDomain); `.

Example:

http://jibbering.com/faq/example/postMessage.html

Where ` window.postMessage ` is not supported, the ` window.name ` property
can be set on the other window, which can poll for updates to that
property using ` setInterval(checkWinName, 100); ` where ` checkWinName `
is a function that polls to check the value of
` self.name `.

http://en.wikipedia.org/wiki/Same_origin_policy

http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html

https://developer.mozilla.org/en/DOM/window.postMessage

http://msdn.microsoft.com/en-us/library/cc197015(VS.85).aspx


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

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

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






In comp.lang.javascript message <4ae386fe$0$279$14726298 (AT) news (DOT) sunsite.dk
Quote:
, Sat, 24 Oct 2009 23:00:02, FAQ server <javascript (AT) dotinternet (DOT) be
posted:

Quote:
or from the ` IFRAME ` or ` FRAME ` element:

var iframeEl = document.getElementById("myFrame");
var fwin = iframeEl.contentWindow;

Perhaps it is worth subdividing, for clarity :

How do I access the content of a frame or iframe

Domain considerations

Frame

Iframe



I've been accessing a page in an iframe with
<iframe>.contentDocument.body.innerHTML // FF Op Sf Cr
<iframe>.contentDocument.body.innerText // Not Firefox?
but I there have no interest in accessing variables. Using IE8, the
code fails at an earlier stage.

In effect, I want to read the file, HTML or TXT, as it exists on disc.


QUERY : disregarding unlikely server & browser settings, which
extensions are taken to imply that the file can safely be read into an
iframe and parsed or read textually there?
(a) HTM HTML SHTML
(b) TXT
(c) *not* ZIP EXE GIF, for example.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

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

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



Dr J R Stockton wrote:
Quote:
In effect, I want to read the file, HTML or TXT, as it exists on disc.
You cannot do it for the reason explained at
http://groups.google.com/group/comp.lang.javascript/msg/d9f3f6724bada573

To read HTML as it exists on disc you have to either
i) read it over a plain text editor on the computer in question
ii) read it as text input stream by using AJAX request.

Anything else simply generates a request to the browser parser to read
the existing DOM Tree resulted from the original page and to back-
parse it to HTML code by the match rules of this particular parser.
The results normally are as an Old Slavonic being translated to
Mandarin and from Mandarin to English by a Spanish native speaker.

Quote:
QUERY : disregarding unlikely server & browser settings, which
extensions are taken to imply that the file can safely be read into an
iframe and parsed or read textually there?
see above

Quote:
(c) *not* ZIP EXE GIF, for example.

--
*(c) John Stockton, nr London, UK. * *?... (AT) merlyn (DOT) demon.co.uk * * Turnpike v6.05.
*Web *<URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links,acronyms
*PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
*Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

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

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



In comp.lang.javascript message <963d3089-ac6c-47a7-8fec-e2f5f3617de5@l3
4g2000vba.googlegroups.com>, Sun, 25 Oct 2009 17:00:29, VK
<schools_ring (AT) yahoo (DOT) com> posted:
Quote:
Dr J R Stockton wrote:
In effect, I want to read the file, HTML or TXT, as it exists on disc.

You cannot do it for the reason explained at
http://groups.google.com/group/comp.lang.javascript/msg/d9f3f6724bada573
Unconvincing, because I *am* doing it, 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.

Quote:
To read HTML as it exists on disc you have to either
i) read it over a plain text editor on the computer in question
i.i) use TYPE or MORE at the command line
i.ii) read it with a text viewer
Quote:
ii) read it as text input stream by using AJAX request.

Anything else simply generates a request to the browser parser to read
the existing DOM Tree resulted from the original page and to back-
parse it to HTML code by the match rules of this particular parser.
Note, though, that "want" can mean more than "need".

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, so
that the output of innerHTML has to be used and purified before use.


FYI, the unanswered "missing page" detection which I raised on
2009-10-15 is now fully dealt with.


Quote:
--
*(c)
DQS


--
(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
  #5  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

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



Dr J R Stockton wrote:

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

Suppose `iframe' refers to the object implementing the HTMLIFrameElement
interface, then you are looking for

iframe.contentDocument.documentElement.textContent

That is, if the layout engine (like Gecko) wraps the content of a text/plain
resource in a markup (HTML-like) document. More precise would be

iframe.contentDocument.body.textContent

then. I remember to have posted that explanation before, but the FAQ had
not been updated for some reason.

Quote:
so that the output of innerHTML has to be used and purified before use.
Non sequitur.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

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

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



In comp.lang.javascript message <3363483.cEBGB3zze1 (AT) PointedEars (DOT) de>,
Tue, 27 Oct 2009 19:38:40, Thomas 'PointedEars' Lahn
<PointedEars (AT) web (DOT) de> posted:
Quote:
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? It's still
annoying that one major browser lacks what others have (even if out of
fashion), especially if the functionality is present.


Quote:
Suppose `iframe' refers to the object implementing the HTMLIFrameElement
interface, then you are looking for

iframe.contentDocument.documentElement.textContent

That is, if the layout engine (like Gecko) wraps the content of a text/plain
resource in a markup (HTML-like) document. More precise would be
You should know better than to suggest, or appear to suggest, writing
engine-dependent code in the default Web context.


Quote:
iframe.contentDocument.body.textContent

then. I remember to have posted that explanation before, but the FAQ had
not been updated for some reason.
Yes, the FAQ maintainer clearly does not understand how the job should
be done. If a change is worth making (and there is either no doubt or a
reasonable consensus), then it is worth making immediately.



<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

--
(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
  #7  
Old   
Garrett Smith
 
Posts: n/a

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



Dr J R Stockton wrote:
Quote:
In comp.lang.javascript message <3363483.cEBGB3zze1 (AT) PointedEars (DOT) de>,
Tue, 27 Oct 2009 19:38:40, Thomas 'PointedEars' Lahn
PointedEars (AT) web (DOT) de> 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? It's still
annoying that one major browser lacks what others have (even if out of
fashion), especially if the functionality is present.


Suppose `iframe' refers to the object implementing the HTMLIFrameElement
interface, then you are looking for

iframe.contentDocument.documentElement.textContent

That is, if the layout engine (like Gecko) wraps the content of a text/plain
resource in a markup (HTML-like) document. More precise would be

You should know better than to suggest, or appear to suggest, writing
engine-dependent code in the default Web context.


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.

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

Quote:
Yes, the FAQ maintainer clearly does not understand how the job should
be done. If a change is worth making (and there is either no doubt or a
reasonable consensus), then it is worth making immediately.



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.

Did you post an example of code that causes the error?
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/

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

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



Dr J R Stockton wrote:

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

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?

Quote:
Suppose `iframe' refers to the object implementing the HTMLIFrameElement
interface, then you are looking for

iframe.contentDocument.documentElement.textContent

That is, if the layout engine (like Gecko) wraps the content of a
text/plain
resource in a markup (HTML-like) document. More precise would be

You should know better than to suggest, or appear to suggest, writing
engine-dependent code in the default Web context.
No, because I am aware of the concept of graceful degradation supported by
feature-testing. You should know better than to assume that I would
recommend to use this code untested.

Quote:
iframe.contentDocument.body.textContent

then. I remember to have posted that explanation before, but the FAQ had
not been updated for some reason.

Yes, the FAQ maintainer clearly does not understand how the job should
be done. If a change is worth making (and there is either no doubt or a
reasonable consensus), then it is worth making immediately.
ACK

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?


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

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

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



Thomas 'PointedEars' Lahn wrote:
Quote:
Dr J R Stockton wrote:

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

Quote:
then. I remember to have posted that explanation before, but the FAQ had
not been updated for some reason.
Yes, the FAQ maintainer clearly does not understand how the job should
be done. If a change is worth making (and there is either no doubt or a
reasonable consensus), then it is worth making immediately.

ACK

If there is another reason for complaining, it has not been provided.

I've heard the complaint about innerText/textContent not being mentioned
in relation to frames and replied.

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.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/

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

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



Garrett Smith wrote:

Quote:
Dr J R Stockton wrote:
Thomas 'PointedEars' Lahn posted:
Suppose `iframe' refers to the object implementing the HTMLIFrameElement
interface, then you are looking for

iframe.contentDocument.documentElement.textContent

That is, if the layout engine (like Gecko) wraps the content of a
text/plain
resource in a markup (HTML-like) document. More precise would be

You should know better than to suggest, or appear to suggest, writing
engine-dependent code in the default Web context.

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.

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.


PointedEars
___________
¹ <http://stats.getjar.com/statistics/world/manufacturer/BlackBerry>
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

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.