【问题标题】:How to embed a facebook page in an iframe?如何在 iframe 中嵌入 Facebook 页面?
【发布时间】:2011-07-18 04:31:19
【问题描述】:

对于我的应用程序,我需要在 iframe 中嵌入 Facebook 页面,这是 html 代码:

<html>
<head></head>
<body>
<iframe src="http://www.facebook.com" style="width:100%;height:100%">
</body>
</html>

但它不起作用,知道为什么以及如何规避吗?

【问题讨论】:

    标签: facebook iframe


    【解决方案1】:

    首先, 请记住以“https://”而不是“http://”开头的 href 值。 注意:您不应在“href”之后放置任何大括号。

    考虑到这一点,现在请尝试下面的代码。

    <iframe src="https://www.facebook.com/plugins/page.php?href={your_facebook_page}&tabs=timeline&width=340&height=300&small_header=false&adapt_container_width=true&hide_cover=false&show_facepile=true&appId" width="340" height="300" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowfullscreen="true" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share"></iframe>
    

    【讨论】:

      【解决方案2】:

      您可以通过您的服务器代理请求。基本上从您的服务器https://example.com?url=facebook.com 请求网址,然后编写一些逻辑让您的服务器请求加载页面所需的所有网址。我不会将它用于任何商业广告,但是因为它不会让 facebook 开心。

      更好的解决方案是使用 facebook iframe。您可以以编程方式将任何 fb 页面 url 转换为 url fb 允许您插入 iframe。查看他们的文档以获取更多信息。对于 fb 页面,它可以完美运行。

      【讨论】:

        【解决方案3】:

        您必须检查这些站点的 HTTP 响应标头 X-Frame-Option。如果其值为“DENY 或 SAMEORIGIN”,则无法在 iframe 中加载这些网站。

        DENY = 没有人可以在 iframe 中加载网站。即使是同一个域页面也无法加载。 SAMEORIGIN = 只有同域的页面才能在 iframe 中加载该网站。

        【讨论】:

          【解决方案4】:

          现在它正在工作。示例代码如下:

          faceframe.html

          &lt;iframe src="file:///C:/Users/Zishan Ahamed/Desktop/ff1.html" width="100%" height="350px" border="0" scrolling="auto" /&gt;&lt;/iframe&gt;

          ff1.html

          &lt;meta http-equiv="refresh" content="0; url=https://facebook.com/" /&gt;

          打开faceframe.html...

          现在完成了。试试它的工作原理...

          【讨论】:

          • 它不起作用,浏览器不允许将本地文件加载到 iframe,如果您尝试从服务器加载 html,则会收到“拒绝在框架中显示 'm.facebook.com',因为它将“X-Frame-Options”设置为“拒绝”。”
          【解决方案5】:

          我知道这有点老了 - 但当我在寻找类似的答案时,它出现在我的搜索中。您可以从以下页面获取代码以嵌入包含公共帖子、cmets 等(有点像 YouTube 嵌入)的 iframe:https://developers.facebook.com/docs/plugins/embedded-posts/ 使用社交插件。不过,我认为 Facebook 永远不会允许您对整个网站进行 iframe。

          【讨论】:

            【解决方案6】:

            我相信 facebook 是一个反框架脚本。它会检测它是否在 iframe 中并显示一个徽标,当您单击该徽标时,它会将您带出 iframe。也许他们有一个允许首先进行身份验证的 sdk,然后它将允许 iframe。我不知道。

            更多信息:http://developers.facebook.com/search?q=Fb:iframe

            【讨论】:

            • Alex 是正确的,除 facebook 之外的许多网站都这样做,因为您“窃取他们的谷歌果汁”是一种非常不受欢迎的做法。
            • 所以没有办法绕过它?
            • 我不知道有什么办法。如果有,只有他们才能为您提供答案。
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-12-05
            • 2019-11-05
            • 2016-08-23
            • 1970-01-01
            相关资源
            最近更新 更多