最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Refused to display a website in a frame because of its 'X-Frame-Options' - Stack Overflow

programmeradmin1浏览0评论

I'm trying to display Facebook page in an simple HTML page which only contains an iframe.

Here's my HTML code:

<html>
    <body>
        <iframe src=""></iframe>
    </body>
</html>

I'm always getting this error in Google Chrome's console:

Refused to display '/' in a frame because it set 'X-Frame-Options' to 'DENY'.

BTW, I'm having this problem also with these iframes:

<iframe src=""></iframe>
<iframe src=""></iframe>
<iframe src=""></iframe>
<iframe src=""></iframe>
<iframe src=""></iframe>
<iframe src=""></iframe>
<iframe src=""></iframe>
<iframe src=""></iframe>
<iframe src=""></iframe>
<iframe src=""></iframe>
<iframe src=""></iframe>

Meanwhile, this iframe is working well !

<iframe src=""></iframe>

How to solve this ?

EDIT based on comments:
Is there an alternative of using iframe if this is unsolvable ? Something like browser tag in XUL ? I already tried browser tag in Firefox extension and it works well, but I'm now coding a chrome extension, so I cannot depend on XUL anymore ?

I'm trying to display Facebook page in an simple HTML page which only contains an iframe.

Here's my HTML code:

<html>
    <body>
        <iframe src="http://www.facebook.com"></iframe>
    </body>
</html>

I'm always getting this error in Google Chrome's console:

Refused to display 'http://www.facebook.com/' in a frame because it set 'X-Frame-Options' to 'DENY'.

BTW, I'm having this problem also with these iframes:

<iframe src="https://mail.google.com/mail/mu/mp/any"></iframe>
<iframe src="http://m.facebook.com"></iframe>
<iframe src="http://m.youtube.com"></iframe>
<iframe src="http://m.dropbox.com"></iframe>
<iframe src="http://m.yahoo.com"></iframe>
<iframe src="http://www.google.com"></iframe>
<iframe src="http://mail.google.com"></iframe>
<iframe src="http://www.facebook.com"></iframe>
<iframe src="http://www.youtube.com"></iframe>
<iframe src="http://www.dropbox.com"></iframe>
<iframe src="http://www.yahoo.com"></iframe>

Meanwhile, this iframe is working well !

<iframe src="http://www.google.com/custom"></iframe>

How to solve this ?

EDIT based on comments:
Is there an alternative of using iframe if this is unsolvable ? Something like browser tag in XUL ? I already tried browser tag in Firefox extension and it works well, but I'm now coding a chrome extension, so I cannot depend on XUL anymore ?

Share Improve this question edited Oct 2, 2013 at 13:28 Ashraf Bashir asked Oct 2, 2013 at 13:20 Ashraf BashirAshraf Bashir 9,80415 gold badges60 silver badges83 bronze badges 5
  • 7 You can't solve this. They're blocking their content fro being loaded in frames which is what you're doing. – John Conde Commented Oct 2, 2013 at 13:21
  • 2 That's because "Refused to display 'facebook.com' in a frame because it set 'X-Frame-Options' to 'DENY'." In other words, Facebook set X-Frame-Options to DENY, to stop you from putting them in an iFrame. – Rich Bradshaw Commented Oct 2, 2013 at 13:22
  • Is there an alternative of using iframe ? something like "browser tag" in XUL ? I already tried browser tag in Firefox extension and it works well, but I'm now writing chrome extension, so I cannot depend on XUL anymore – Ashraf Bashir Commented Oct 2, 2013 at 13:23
  • 4 This is why Facebook, Twitter and many other services expose their API through SDK's. They don't want you loading their content in an iFrame. If you are going to load it, it has to be through the proper channels. See developers.facebook.com – War10ck Commented Oct 2, 2013 at 13:25
  • 1 You should propably rephrase this question and ask it again with tags related to chrome and plugin dev. – MildlySerious Commented Oct 2, 2013 at 13:33
Add a comment  | 

2 Answers 2

Reset to default 8

Yes, you could

  • use server-side includes, to fetch it from the server and include it in an iframe
  • use a custom browser which does not recognize that header
  • complicated: use websockets to create your own Javascript HTTP client, fetch the page, and insert it into the DOM

For those who are interested, this cannot be done !

发布评论

评论列表(0)

  1. 暂无评论