Getting HTML Contents of a Frame

D

DRS.Usenet

When I run
Code:
alert("page contents:" + content.document.documentElement.innerHTML);

I am able to pull the content. I see something like this

Code:
page contents:<head><title>A Title</title>
<FRAMESET ROWS="75,*">
<FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
<FRAME SRC="sample.html" NAME="body" title="Main Content">
</FRAMESET>

What I want to get is the HTML inside of one of the frames,
specifically "sample.html".

I am able to get to an HTMLFrameElement object using
"content.document.getElementsByName("body")[0]", but have not been
able to grab the content, and I'm not so sure that's the right path to
be taking to get the content.

Can somebody please help me out?

--Dale--
 
P

Peter Michaux

When I run
Code:
alert("page contents:" + content.document.documentElement.innerHTML);[/QUOTE]


I didn't know "content" would access the window object. I think it is
far more standard to write window.document....
[QUOTE]

I am able to pull the content. I see something like this

Code:
page contents:<head><title>A Title</title>
<FRAMESET ROWS="75,*">
<FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
<FRAME SRC="sample.html" NAME="body" title="Main Content">
</FRAMESET>

What I want to get is the HTML inside of one of the frames,
specifically "sample.html".

window.body.documentElement.innerHTML

where "body" is the NAME attribute of the frame. Probably better to
choose a different name since "body" has special meaning in a
document.


Peter
 
D

DRS.Usenet

Thank you very much for the reply Peter. Please see comments below.

When I run
Code:
alert("page contents:" + content.document.documentElement.innerHTML);[/QUOTE]

I didn't know "content" would access the window object. I think it is
far more standard to write window.document....[/QUOTE]

I could have been more descriptive.  In my case, "window.document..."
doesn't work, and "content.document..." does (at least for the page
with the frameset).  The likely wild card: I am running from an
overlay in a Firefox extension.
[QUOTE][QUOTE]
I am able to pull the content.  I see something like this[/QUOTE]
[QUOTE]
[CODE]
page contents:<head><title>A Title</title>
<FRAMESET ROWS="75,*">
<FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
<FRAME SRC="sample.html" NAME="body" title="Main Content">
</FRAMESET>
What I want to get is the HTML inside of one of the frames,
specifically "sample.html".

window.body.documentElement.innerHTML

where "body" is the NAME attribute of the frame. Probably better to
choose a different name since "body" has special meaning in a
document.

The page, at the moment, is authored by me, and I can change "body" to
anything, but once this code gets into doing real work, it will be
somebody else's page, so if they choose "body", I'll need to deal with
it.

So here's what I see so far:

content.document.documentElement.innerHTML shows the page contents
(the page with the frameset).

Based on your suggestion to use "window" instead of "content", I tried
this, which should work, but doesn't:

window.document.documentElement.innerHTML says "undefined".

content.body.documentElement.innerHTML gives a TypeError: content.body
has no properties.

I renamed "body" to see if it made any difference...

content.dale.documentElement.innerHTML says content.dale has no
properties

window.dale.documentElement.innerHTML says window.dale has no
properties

Any more ideas for me?

--Dale--
 
D

DRS.Usenet

Anybody? This javascript code is running from a Firefox plugin, if
that makes any difference.
 
D

DRS.Usenet

When I run
Code:
alert("page contents:" + content.document.documentElement.innerHTML);

I am able to pull the content. I see something like this

Code:
page contents:<head><title>A Title</title>
<FRAMESET ROWS="75,*">
<FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
<FRAME SRC="sample.html" NAME="body" title="Main Content">
</FRAMESET>

What I want to get is the HTML inside of one of the frames,
specifically "sample.html".

I am able to get to an HTMLFrameElement object using
"content.document.getElementsByName("body")[0]", but have not been
able to grab the content, and I'm not so sure that's the right path to
be taking to get the content.

The property I was looking for was "contentDocument". Here is the
solution:

content.document.getElementsByName("body")
[0].contentDocument.documentElement.innerHTML

which I was able to assemble once I found the "right" API
documentation here: http://www.xulplanet.com/references/xpcomref/ifaces/nsIDOMHTMLFrameElement.html

Do I get a "5 of 5" for answering my own question?

--Dale--
 
P

Peter Michaux

When I run
Code:
alert("page contents:" + content.document.documentElement.innerHTML);
I am able to pull the content. I see something like this
Code:
page contents:<head><title>A Title</title>
<FRAMESET ROWS="75,*">
<FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
<FRAME SRC="sample.html" NAME="body" title="Main Content">
</FRAMESET>
What I want to get is the HTML inside of one of the frames,
specifically "sample.html".
I am able to get to an HTMLFrameElement object using
"content.document.getElementsByName("body")[0]", but have not been
able to grab the content, and I'm not so sure that's the right path to
be taking to get the content.

The property I was looking for was "contentDocument". Here is the
solution:

content.document.getElementsByName("body")
[0].contentDocument.documentElement.innerHTML

which I was able to assemble once I found the "right" API
documentation here:http://www.xulplanet.com/references/xpcomref/ifaces/nsIDOMHTMLFrameEl...


There seems to be problems getting the document object of a frame.
About half way down this page...

<URL: http://developer.apple.com/internet/webcontent/iframe.html>

Peter
 
D

DRS.Usenet

On Jun 15, 10:44 am, "(e-mail address removed)"
The property I was looking for was "contentDocument". Here is the
solution:
content.document.getElementsByName("body")
[0].contentDocument.documentElement.innerHTML

which I was able to assemble once I found the "right" API
documentation here:http://www.xulplanet.com/references/xpcomref/ifaces/nsIDOMHTMLFrameEl...

There seems to be problems getting the document object of a frame.
About half way down this page...

<URL:http://developer.apple.com/internet/webcontent/iframe.html>

For me, since my code will only run as a Firefox plug-in (hopefully
someday, that is), the typical tooth gnashing about making it run in
Redmond-flavor concurrently with other flavors doesn't apply for me.

But that link is a nice wrap-up for googlers needing to run in various
environments. Nice addition to the thread.

--Dale--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top