By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,173 Members | 1,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,173 IT Pros & Developers. It's quick & easy.

Getting HTML Contents of a Frame

P: n/a
When I run
Expand|Select|Wrap|Line Numbers
  1. alert("page contents:" + content.document.documentElement.innerHTML);
  2.  
I am able to pull the content. I see something like this

Expand|Select|Wrap|Line Numbers
  1. page contents:<head><title>A Title</title>
  2. <FRAMESET ROWS="75,*">
  3. <FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
  4. <FRAME SRC="sample.html" NAME="body" title="Main Content">
  5. </FRAMESET>
  6.  
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--

Jun 15 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Jun 15, 7:44 am, "DRS.Use...@sengsational.com"
<DRS.Use...@sengsational.comwrote:
When I run
Expand|Select|Wrap|Line Numbers
  1. alert("page contents:" + content.document.documentElement.innerHTML);
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. I didn't know "content" would access the window object. I think it is
  4. far more standard to write window.document....
  5.  
  6.         
  7.  
  8.  
  9.  
>
I am able to pull the content. I see something like this

Expand|Select|Wrap|Line Numbers
  1. page contents:<head><title>A Title</title>
  2. <FRAMESET ROWS="75,*">
  3. <FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
  4. <FRAME SRC="sample.html" NAME="body" title="Main Content">
  5. </FRAMESET>
  6.  

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

Jun 15 '07 #2

P: n/a
Thank you very much for the reply Peter. Please see comments below.

On Jun 15, 1:42 pm, Peter Michaux <petermich...@gmail.comwrote:
On Jun 15, 7:44 am, "DRS.Use...@sengsational.com"

<DRS.Use...@sengsational.comwrote:
When I run
[code]
alert("page contents:" + content.document.documentElement.innerHTML);

I didn't know "content" would access the window object. I think it is
far more standard to write window.document....
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.
I am able to pull the content. I see something like this
Expand|Select|Wrap|Line Numbers
  1.  page contents:<head><title>A Title</title>
  2.  <FRAMESET ROWS="75,*">
  3.  <FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
  4.  <FRAME SRC="sample.html" NAME="body" title="Main Content">
  5.  </FRAMESET>
  6.  
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--

Jun 15 '07 #3

P: n/a
Anybody? This javascript code is running from a Firefox plugin, if
that makes any difference.

On Jun 15, 10:44 am, "DRS.Use...@sengsational.com"
<DRS.Use...@sengsational.comwrote:
When I run
Expand|Select|Wrap|Line Numbers
  1. alert("page contents:" + content.document.documentElement.innerHTML);
  2.  

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

Expand|Select|Wrap|Line Numbers
  1. page contents:<head><title>A Title</title>
  2. <FRAMESET ROWS="75,*">
  3. <FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
  4. <FRAME SRC="sample.html" NAME="body" title="Main Content">
  5. </FRAMESET>
  6.  

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

Jun 16 '07 #4

P: n/a
On Jun 15, 10:44 am, "DRS.Use...@sengsational.com"
<DRS.Use...@sengsational.comwrote:
When I run
Expand|Select|Wrap|Line Numbers
  1. alert("page contents:" + content.document.documentElement.innerHTML);
  2.  

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

Expand|Select|Wrap|Line Numbers
  1. page contents:<head><title>A Title</title>
  2. <FRAMESET ROWS="75,*">
  3. <FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
  4. <FRAME SRC="sample.html" NAME="body" title="Main Content">
  5. </FRAMESET>
  6.  

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/...meElement.html

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

--Dale--

Jun 17 '07 #5

P: n/a
On Jun 17, 7:01 am, "DRS.Use...@sengsational.com"
<DRS.Use...@sengsational.comwrote:
On Jun 15, 10:44 am, "DRS.Use...@sengsational.com"

<DRS.Use...@sengsational.comwrote:
When I run
Expand|Select|Wrap|Line Numbers
  1.  alert("page contents:" + content.document.documentElement.innerHTML);
  2.  
I am able to pull the content. I see something like this
Expand|Select|Wrap|Line Numbers
  1.  page contents:<head><title>A Title</title>
  2.  <FRAMESET ROWS="75,*">
  3.  <FRAME SRC="sample2.html" NAME="nav" title="Main Navigation">
  4.  <FRAME SRC="sample.html" NAME="body" title="Main Content">
  5.  </FRAMESET>
  6.  
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/...DOMHTMLFrameEl...

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

Jun 17 '07 #6

P: n/a
On Jun 17, 1:31 pm, Peter Michaux <petermich...@gmail.comwrote:
On Jun 17, 7:01 am, "DRS.Use...@sengsational.com"
<DRS.Use...@sengsational.comwrote:
On Jun 15, 10:44 am, "DRS.Use...@sengsational.com"
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/...DOMHTMLFrameEl...

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

Jun 18 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.