简体   繁体   English

在iframe中获取img标签

[英]Getting the img tag inside iframe

I have an iframe with a class name="blaclass". 我有一个类名为“ blaclass”的iframe。 Inside it, I have one div with no name (or id) and inside this id there is a div with class name = "classs". 在其中,我有一个没有名称(或ID)的div,在此ID中,有一个类名称为“ classs”的div。 Inside this div, lie two images (with no class name/id). 在这个div内,放置两个图像(没有类名/ ID)。

How can I get those image.src? 如何获得这些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). PS:在页面完全呈现之前,我无法添加类名称/ id(我不是在创建iframe,而是通过javascript动态创建的,之后我会运行脚本)。

Thx 谢谢

a.html: a.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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: b.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>

Also be sure the domain which the iframe is on is the same as the one its pointing to. 另外,请确保iframe所在的域与其指向的域相同。 Otherwise you won't be able to get any information from the iframe. 否则,您将无法从iframe获取任何信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM