【问题标题】:Iframe not displaying some pagesiframe 不显示某些页面
【发布时间】:2012-02-10 09:00:58
【问题描述】:

在 iframe 中显示某些网站时遇到问题。 Live example of code

这个有效。

  <article class='nobackground'>
    <iframe src='http://en.wikipedia.org/wiki/<?php echo $myid ?>'></iframe>
  </article>

这个不显示。 (youtube、google 或 facebook 也不会,但是静态 html 似乎可以正常显示)

   <article class='nobackground'>
    <iframe src='http://www.google.ie/search?tbm=isch&hl=en&source=hp&biw=1280&bih=679&q=<?php echo $myid ?>'></iframe>
  </article>

使用的 CSS:

 iframe {
      width: 100%;
      height: 620px;
      background: white;
      border: 1px solid rgb(192, 192, 192);
      margin: -1px; 
 }

 article.fill iframe {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      border: 0;
      margin: 0;
      border-radius: 10px;
      -o-border-radius: 10px;
      -moz-border-radius: 10px;
      -webkit-border-radius: 10px;
      z-index: -1;
 }

【问题讨论】:

  • 有关 X-Frame-Option 标头的说明,请参阅 this post
  • 呃...你为什么要做&lt;body style='display: none'&gt;“这里没什么可看的,继续前进....”

标签: php html iframe


【解决方案1】:

Google 和许多其他公司禁止通过 Javascript(使用 top.location 检测当前框架)和 Grzegorz Grzybek 提到的 X-Frame-Option 标头(禁止兼容浏览器的框架)对内容进行 iframe。

如果您想捕获内容,您必须编写一个变通页面,该页面执行 file_get_content() 或 cURL 调用以获取页面代码并稍微修改代码(使 URL 成为绝对,删除不需要的脚本)然后将代码回显到本地页面。

【讨论】:

    【解决方案2】:

    您不能 iframe Google 或其他网站,因为它们的 X-Frame-Options 通过标头发送。您的浏览器尊重这一点,并拒绝显示您尝试链接的页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-17
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多