How to get iFrame src content using javascript?

倾然丶 夕夏残阳落幕 提交于 2019-12-18 05:58:23

问题


I have an iFrame, content of which is inside another iFrame. I want to get the inside iFrame's src content. How can I do this using javascript?


回答1:


The outer page:

<html>
<body>
<iframe id="ifr1" src="page1.htm"></iframe>
<iframe id="ifr2" src="http://www.google.com"></iframe>
</body>
</html>

page1.htm:

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



回答2:


iframeInstance.contentWindow.document - this document loaded from SRC url. and vice verse - to get from inner document to parent use: parent.document




回答3:


<body>
<div id="f1" style="padding-left:5px;">..</div>

<script type="text/javascript">
document.getElementById("f1").innerHTML = '<iframe src="frame.php or html" width="200" height="100" frameborder="0" scrolling="no"></iframe>';
</script>
</body>
</html>


I am not so expert but this for your script hints, you can modify and test for your pages.



来源:https://stackoverflow.com/questions/1264569/how-to-get-iframe-src-content-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!