【问题标题】:Display another website like iframe in PHP在 PHP 中显示另一个网站,如 iframe
【发布时间】:2014-03-14 11:57:28
【问题描述】:

我想在 div 中显示另一个网站。它用于截取该 div 的屏幕截图。我不得不限制 div 的高度。我该怎么做。我不能使用 iframe。因为很多网站不支持 iframe。我正在使用下面的 php 代码来显示一个网站。我怎样才能限制高度(如果可能也是宽度)....

<div id="target">
<?php
$url=$_GET['url'];
echo file_get_contents($url);
?>
</div>

【问题讨论】:

  • 在许多网站上,这可能无法正常工作。他们的 CSS、脚本、URL、图片等可能没有被正确引用。

标签: php html css iframe screenshot


【解决方案1】:

使用 CSS 可以限制 DIV 的宽度高度,例如:

#target{
  width:400px;
  height:400px;
  overflow:hidden; /* optional - or scroll */
}

请注意,如果不使用 iframe 或相当复杂的技术,您最终不会以任何类似的保真度显示外部网站的内容,如果媒体/资源繁重,则更少。

【讨论】:

    【解决方案2】:

    您好,您是否尝试将 max-width 和 max-height 添加到您的 css 中:

    #target{
        max-width:300px;
        max-height:300px;
        overflow: auto;
    }
    

    Exemple JSFiddle

    【讨论】:

      猜你喜欢
      • 2017-04-10
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 2016-10-30
      • 2011-10-15
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      相关资源
      最近更新 更多