Iframe not displaying some pages

流过昼夜 提交于 2019-12-25 07:48:10

问题


Having issues displaying some websites within iframes. Live example of code

This one works.

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

This one does not display. (neither will youtube, google or facebook, however static html seems to display fine)

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

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

回答1:


Google and many others forbid iframing of content through both Javascript (using top.location to detect current framing) and the X-Frame-Option header mention by Grzegorz Grzybek (which forbids framing for compliant browsers).

If you want to capture content you'll have to write a work-around page that does a file_get_content() or cURL call to fetch the code of the page and modify the code slightly (make URLs absolute, remove unwanted scripts) and then echo the code onto a local page.




回答2:


You cannot iframe Google or other sites because of their X-Frame-Options sent through with the header. Your browser respects this and refuses to show the page you are trying to link.



来源:https://stackoverflow.com/questions/8862755/iframe-not-displaying-some-pages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!