繁体   English   中英

使用 PHP 文件加载外部网站

[英]Loading external website with PHP file

我正在使用 JQuery 来调整 iframe 的大小以使其具有与内容相同的高度,尽管它仅在内容位于同一域中时才可以正常工作。

我需要显示外部内容,所以我让 iframe 指向我服务器中的一个文件,该文件又应该显示外部内容:

<iframe src="frame.php" scrolling="no" frameborder="0" noresize="noresize" style="width:100%; border: 1px solid black;">

如何使 frame.php 显示外部域的内容?

如果您需要更多信息,这里是关于如何操作的答案(他解释了所有内容,除了如何在 php 文件中显示内容): AutoHeight IFrame

谢谢

所以你想获取外部网站的内容?

这将起作用,但是当目标页面具有非绝对 URL 和相对链接时,它会破坏布局:

框架.php

<?php

echo file_get_contents($_GET['url']);

?>

<?php echo file_get_contents( "http://example.com" );?>

这样的事情会做

不幸的是,php 不是执行此操作的正确语言。 In order to determine the height of the document in the iframe, you would need to make a javascript call from the parent document (where the iframe element is) to the document referenced in the src of the iframe.

如果 iframe 的src在您的域上,则您拥有使用文档的 DOM 获取文档高度的完全权限,根据同源策略。 当您从另一个域加载文档时,您无权查询高度。 您的问题的回答者似乎建议的是在您的网站上设置代理,以便规避相同的来源政策。

但是,会有其他问题(即代理页面上的相对链接等)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM