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

simple iframe, calling with innerHTML - what am i doing wrong here?

P: n/a
....[something.htm]

<div id=work>hello</div>
....[somethingelse.htm]

<IFRAME id="thisframe" src="./something.htm"></IFRAME>

<script>
document.frames("thisframe").getElementById("work" ).innerHTML =
"goodbye"
</script>

Thank you

Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a

<Ra*********@hotmail.com> schreef in bericht
news:11********************@f14g2000cwb.googlegrou ps.com...
...[something.htm]

<div id=work>hello</div>
...[somethingelse.htm]

<IFRAME id="thisframe" src="./something.htm"></IFRAME>

<script>
document.frames("thisframe").getElementById("work" ).innerHTML =
"goodbye"
</script>

Thank you


change to:
document.frames("thisframe").getElementById("work" ).body.innerHTML =

grt Bert
Jul 23 '05 #2

P: n/a

"Bert" <b.******@chello.nl> schreef in bericht
news:ST*********************@amsnews05.chello.com. ..

<Ra*********@hotmail.com> schreef in bericht
news:11********************@f14g2000cwb.googlegrou ps.com...
...[something.htm]

<div id=work>hello</div>
...[somethingelse.htm]

<IFRAME id="thisframe" src="./something.htm"></IFRAME>

<script>
document.frames("thisframe").getElementById("work" ).innerHTML =
"goodbye"
</script>

Thank you


change to:
document.frames("thisframe").getElementById("work" ).body.innerHTML =

grt Bert


sorry, makes nog sense...
Jul 23 '05 #3

P: n/a

<Ra*********@hotmail.com> schreef in bericht
news:11********************@f14g2000cwb.googlegrou ps.com...
...[something.htm]

<div id=work>hello</div>
...[somethingelse.htm]

<IFRAME id="thisframe" src="./something.htm"></IFRAME>

<script>
document.frames("thisframe").getElementById("work" ).innerHTML =
"goodbye"
</script>

Thank you


document.frames("thisframe").document.getElementBy Id("work").innerHTML =
"goodbye";

that might be better...
Jul 23 '05 #4

P: n/a
Hmm, tried both and still can't get it to work. I'm yanking my hair out
with this one. Nothing seems to work! Have you tested it out?

Jul 23 '05 #5

P: n/a
Hmm, tried both and still can't get it to work. I'm yanking my hair out

with this one. Nothing seems to work! Any ideas?

Jul 23 '05 #6

P: n/a
here's the source I tested it with:


<html>

<script>
function test()
{

document.frames("thisframe").document.getElementBy Id("work").innerHTML =
"goodbye";

}
</script>

<body onload = "test()">
<IFRAME id="thisframe" src="./something.htm"></IFRAME>

</body>
</html>

Jul 23 '05 #7

P: n/a
Interesting. Why does it error out if you remove test(); from body
onload? Anyway to make it a seperate call function, like <script>
test(); </script> somewhere else?

Jul 23 '05 #8

P: n/a
Thank you -- works perfectly... Have a great weekend! :)))

Sincerely --

Alex

Jul 23 '05 #9

P: n/a
DU
Followup-to: comp.lang.javascript only

Ra*********@hotmail.com wrote:
...[something.htm]

<div id=work>hello</div>
...[somethingelse.htm]

<IFRAME id="thisframe" src="./something.htm"></IFRAME>

<iframe name="thisframe" src="./something.htm"></iframe>


<script>
document.frames("thisframe").getElementById("work" ).innerHTML =
- frames collection are a property of the window object, not of the
document.
- you can access a single frame within the frames collection with
frames["FrameName"] or with frames.FrameName but not with
frames("IframeId"). You're confused in the correct way to access a frame.
- when accessing a frame, the returned object is a window object, not a
document.
- contentDocument is a property of the iframe object which can return a
reference to the document contained in the iframe. So assuming:

<iframe id="idIframe" ...></iframe>

then you can access such iframed document like this:

document.getElementById("idIframe").contentDocumen t

"goodbye"
</script>

Thank you

<head>
....
<script type="text/javascript">
function PopulateIframe()
{
var IframedDocumentBody = frames["thisframe"].document.body;
var FirstParg = document.createElement("p");
FirstParg.appendChild(document.createTextNode("goo dbye"));
IframedDocumentBody.appendChild(FirstParg);
}
</script>
</head>

<body onload="PopulateIframe();">
....

Not tested but should work in Mozilla-based browsers.

DU
Followup-to: comp.lang.javascript only
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.5 :)
Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.