문제

클래스 이름 = "blaclass"가있는 iframe이 있습니다. 그 안에는 이름 (또는 ID)이없는 하나의 div가 있고이 ID 안에는 클래스 이름 = "classs"가있는 div가 있습니다. 이 div 내부에는 두 개의 이미지가 있습니다 (클래스 이름/ID 없음).

해당 image.src를 어떻게 얻을 수 있습니까? 프로토 타입 버전이 더 좋으면!

추신 : 페이지가 완전히 렌더링되기 전에 클래스 이름/ID를 추가 할 수 없습니다 (iframe을 만들지 않습니다. JavaScript를 통해 동적으로 생성되고 그 후 스크립트를 실행합니다).

고마워

도움이 되었습니까?

해결책

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 :

<!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>

다른 팁

또한 Iframe이 켜져있는 도메인이 지적하는 도메인과 동일합니다. 그렇지 않으면 iframe에서 정보를 얻을 수 없습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top