最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting the img tag inside iframe - Stack Overflow

programmeradmin3浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论