Forum Moderators: open

Message Too Old, No Replies

how to use method getElementById()?

with iframe inside my page

         

g8tuananh

6:29 pm on Dec 5, 2006 (gmt 0)

10+ Year Member



this is code:
<script>
function getElem()
{
alert(getElementById("div1").innerHTML);
}
</script>

<body>
<iframe src="exam.htm"></iframe>
<a herf="#" onclick="getElem()">invoke</a>
</body>

------
exam.htm

<body>
<div id="div1"></div>
</body>

anybody how can i get property innerHTML of object div in this case?
thanks

Trace

7:21 pm on Dec 5, 2006 (gmt 0)

10+ Year Member



Here ya go;

alert(document.frames[0].document.getElementById("div1").innerHTML);

penders

11:23 pm on Dec 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think Trace's solution will work OK in Opera, but for FF, IE (and Opera) I believe you need to reference the contentWindow property of the IFRAME in order to access the containing document... eg:

alert(document.frames[0].contentWindow.document.getElementById("div1").innerHTML);