I have an iframe with a class name="blaclass". Inside it, I have one div with no name (or id) and inside this id there is a div with class name = "classs". Inside this div, lie two images (with no class name/id).
How can I get those image.src? If there is a Prototype version even better!
PS: I cannot add class names/ids before the page renders fully (I am not creating the iframe - it's created dynamically via javascript and I run my script AFTER that).
Thx
I have an iframe with a class name="blaclass". Inside it, I have one div with no name (or id) and inside this id there is a div with class name = "classs". Inside this div, lie two images (with no class name/id).
How can I get those image.src? If there is a Prototype version even better!
PS: I cannot add class names/ids before the page renders fully (I am not creating the iframe - it's created dynamically via javascript and I run my script AFTER that).
Thx
Share Improve this question asked Jan 29, 2009 at 9:59 Jon RomeroJon Romero 4,1006 gold badges38 silver badges34 bronze badges2 Answers
Reset to default 2a.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml" xml:lang="en" lang="en">
<body onLoad="foo()">
<iframe src="b.html">
</iframe>
<script type="text/javascript">
function foo()
{
alert(window.frames[0].document.getElementsByClassName("classs")[0].getElementsByTagName("img")[0].src);
}
</script>
</body>
</html>
b.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml" xml:lang="en" lang="en">
<body>
<div>
<div class="classs">
<img id="img" src="test.png" />
<img id="img" src="test.png" />
</div>
</div>
</body>
</html>
Also be sure the domain which the iframe is on is the same as the one its pointing to. Otherwise you won't be able to get any information from the iframe.