有没有办法通过iframe上的JavaScript获取外部页面?

时间:2015-01-15 07:01:00

标签: javascript jquery iframe

我可以使用此

成功加载内部页面的全宽度
<script type="text/javascript">
     function calcHeight()
     {
     //find the height of the internal page
     var the_height=
     document.getElementById('the_iframe').contentWindow.
     document.body.scrollHeight;

     //change the height of the iframe
     document.getElementById('the_iframe').height=
     the_height;
     }
</script>

<iframe width="100%" src="/mypage.php" 
scrolling="no" id="the_iframe" onLoad="calcHeight();" height="1px" frameborder="0" ></iframe>

这适用于任何INTERNAL页面(来自同一域的页面)。我正在努力让它与外部页面(跨域)一起工作,但没有找到任何解决方案。

我觉得切勿进行跨域通信是不可能的,因为我真的没有预料到这一点。无论如何,谢谢你们。

1 个答案:

答案 0 :(得分:1)

无法访问引用跨域网址的iframe内容。