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

Is there any way to get external pagess via JavaScript on iframe?

本文关键字:获取 JavaScript 外部 上的 iframe 有没有      更新时间:2023-09-26

>我能够使用它成功加载全宽的内部页面

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

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

似乎不可能进行跨域通信,我真的没想到。不管怎样,谢谢大家。

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