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

R

Ragnorack67

....[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
 
B

Bert

...[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
 
B

Bert

Bert said:
...[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...
 
B

Bert

...[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.getElementById("work").innerHTML =
"goodbye";

that might be better...
 
R

Ragnorack67

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

Ragnorack67

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

Bert

here's the source I tested it with:




<html>

<script>
function test()
{

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

}
</script>

<body onload = "test()">


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

</body>
</html>
 
R

Ragnorack67

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

DU

Followup-to: comp.lang.javascript only

...[something.htm]

<div id=work>hello</div>


...[somethingelse.htm]

<IFRAME id="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").contentDocument

"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("goodbye"));
IframedDocumentBody.appendChild(FirstParg);
}
</script>
</head>

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

Not tested but should work in Mozilla-based browsers.

DU
Followup-to: comp.lang.javascript only
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top