javascript - Getting the img tag inside iframe - Stack Overflow

I have an iframe with a class name="blaclass".Inside it, I have one div with no name (or id)

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 badges
Add a ment  | 

2 Answers 2

Reset to default 2

a.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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745637191a4637465.html

相关推荐

  • javascript - Getting the img tag inside iframe - Stack Overflow

    I have an iframe with a class name="blaclass".Inside it, I have one div with no name (or id)

    22天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信