如何使用javascript获取iFrame src内容?

Pau*_*raj 7 javascript iframe

我有一个iFrame,其内容在另一个iFrame中.我想获得内部iFrame的src内容.我怎么能用javascript做到这一点?

Jos*_*hua 5

外页:

<html>
<body>
<iframe id="ifr1" src="page1.htm"></iframe>
<iframe id="ifr2" src="http://www.google.com"></iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

page1.htm:

<html>
<body>
<script type="text/javascript">
document.write(parent.document.getElementById('ifr2').src);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)