Iframe not displaying some pages

2019-09-11 07:57发布

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

标签: php html iframe
2条回答
Evening l夕情丶
2楼-- · 2019-09-11 08:49

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.

查看更多
别忘想泡老子
3楼-- · 2019-09-11 08:49

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.

查看更多
登录 后发表回答