Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access the innerhtml of a div inside a frame 2

Status
Not open for further replies.

webmast3r

Programmer
Sep 8, 2003
13
LB
hello.
i have a page (index.html) that has an iframe (normally i will make it either very small or hidden)
the frame points to a url(page1.html)

here's the source of page1.html
Code:
<html>
<head>
<title>page1</title>
</head>
<body>
<div name="content" id="content">contents in here</div>
</body>
</html>
what i want to do is the following:
in index.html i need to show only the innerhtml of the div called content.

so i need the javascript to accomplish this...
index.html should be sthg like
Code:
<html>
<head>
<title>index</title>
</head>
<body>
<iframe url="page1.html" name="f" id="f"></iframe>
<script>document.write(document.getElementById('f').content.innerHTML);</script>
</body>
</html>

thanks in advance
Cheers, Dan
 
Have you tried:
Code:
document.getElementById('f').document.getElementById('content').innerHTML


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
yes i have tried...
that was my first try..
but it gave me a javascript error (object required)

so i changed it to: document.getElementById('f').content.innerHTML

which doesnt give any error, but doesnt show anything as well..

any other hints?
 

Have you tried accessing it through the frames collection?

Code:
document.frames['f'].document.getElementById('content').innerHTML;

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
BRPS is correct! I just tried this and it works:
Code:
var o1 = document.getElementById('showit');
var o2 = document.frames('ifrm').document.getElementById('stuff');
o1.innerHTML = o2.innerHTML;


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
yes i have tried accessing it through the frames collection as well, but no luck..
sory tsdragon , but ur code is not working neither...

again here are the new page1.html and page2.html, maybe am misstyping something...
Code:
<html>
<head>
<title>page1</title>
</head>
<body>
<div name="c" id="c">contents in here</div>
</body>
</html>
Code:
<html>
<head>
<title>page2</title>
</head>
<body>
<iframe src="page1.html" name='f' id='f'></iframe>
<script language="JavaScript">
var o1 = document.getElementById('f').document.getElementById('c');
document.write(o1.innerHTML);
</script>
</body>
</html>

note that i have also tried
document.frames['f']...
and document.frames[0]
i also have tried document.frames('f')
and in the end i have also tried all the options with double quotations instead of single quotations (just in case...)

any suggestions?
thanks again, dan
 
I tested that code, so I know it works. You must have something else wrong too. Here is what I used:

Main form:
Code:
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<style type="text/css">
.ifrm {
    width: 600px;
    height: 200px;
}
</style>
<script>
function ShowMe() {
    var o1 = document.getElementById('showit');
    var o2 = document.frames('ifrm').document.getElementById('stuff');
    o1.innerHTML = o2.innerHTML;
}
</script>
</HEAD>
<BODY onLoad="ShowMe();">
<span id="showit">...</span>
<br>
<br>
<iframe id="ifrm" class="ifrm" noresize src="inframe.html"></iframe><br>
</BODY>
</HTML>

Framed form:
Code:
<html>
<head>
<title>test</title>
</head>
<body>
01. this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test <br>
<span id="stuff"><b><i>some stuff</i></b></span>
</body>

When you load the main form you will see that the span at the top of it shows "some stuff" in bold italic - just what the span on the iframed document contains.



Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
yep man, it works... when i pasted your code exactly as u provided it... it worked!!

anyways, i'll check back why it didnt work in my version... and thanks alot for your great answer..

cheers, Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top