views:

577

answers:

2

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

+1  A: 

a.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/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.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/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>
heeen
+1  A: 

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.

Luca Matteis