Can't show some websites in iframe tag

2019-01-23 15:53发布

问题:

I am trying to develop a page in which I can show more than 3 website at a time, as below:

<ul>
   <li>
      <iframe src="http://www.facebook.com/" /><p> iframe is not supported</p>
   </li>
   <li>
      <iframe src="http://www.yahoo.com/"></iframe>
   </li>
   <li>
      <iframe src="http://www.google.co.in"></iframe>
   </li>
</ul>

The problem is that it shows yahoo.com and google.co.in, but does not display Facebook in the iframe.

回答1:

You have to check for HTTP response header X-Frame-Option of those sites. if its value is "DENY or SAMEORIGIN", then you can not load those website in the iframes.

DENY = No one can load the website in iframe. Even the same domain page wont be able to load. SAMEORIGIN = only a page which is in same domain can load this website in iframe.



回答2:

Since some websites have decided to disable embedding them in iframes theres nothing you can do with pure html solutions. You could create a serverside script (in PHP) that pulls the target site via your webserver and then use the html etc.

The only way I can think of that would enable you to check wether the site has loaded is to search the iframe for a specific element that exists on the target website (for example a div with a specific id or class on the Facebook's front page). The reason would be that different websites can handle being embedded into iframes differently and while some might display some content, some may display nothing etc and the only way to be sure is to check for real elements.



回答3:

facebook does not want you to load there main site in frames

<iframe src="http://m.facebook.com/" width="200" height="300" scrolling="auto" frameborder=0></iframe>

width="200" height="300" can be adjusted accordingly.

What this does is load the mobile version of facebook in the frame instead of the main site.

Reference



回答4:

You will not able to do that, you can only iframe like button... someother not whole site.



回答5:

Use http://devilishdb.koding.com/proxy?facebook.com it's a proxy system I made. I tested it for Google and it works. Hope this helps



标签: html http iframe