【发布时间】: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>
但它不起作用,知道为什么以及如何规避吗?
【问题讨论】:
对于我的应用程序,我需要在 iframe 中嵌入 Facebook 页面,这是 html 代码:
<html>
<head></head>
<body>
<iframe src="http://www.facebook.com" style="width:100%;height:100%">
</body>
</html>
但它不起作用,知道为什么以及如何规避吗?
【问题讨论】:
首先, 请记住以“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>
【讨论】:
您可以通过您的服务器代理请求。基本上从您的服务器https://example.com?url=facebook.com 请求网址,然后编写一些逻辑让您的服务器请求加载页面所需的所有网址。我不会将它用于任何商业广告,但是因为它不会让 facebook 开心。
更好的解决方案是使用 facebook iframe。您可以以编程方式将任何 fb 页面 url 转换为 url fb 允许您插入 iframe。查看他们的文档以获取更多信息。对于 fb 页面,它可以完美运行。
【讨论】:
您必须检查这些站点的 HTTP 响应标头 X-Frame-Option。如果其值为“DENY 或 SAMEORIGIN”,则无法在 iframe 中加载这些网站。
DENY = 没有人可以在 iframe 中加载网站。即使是同一个域页面也无法加载。 SAMEORIGIN = 只有同域的页面才能在 iframe 中加载该网站。
【讨论】:
现在它正在工作。示例代码如下:
faceframe.html
<iframe src="file:///C:/Users/Zishan Ahamed/Desktop/ff1.html" width="100%" height="350px" border="0" scrolling="auto" /></iframe>
ff1.html
<meta http-equiv="refresh" content="0; url=https://facebook.com/" />
打开faceframe.html...
现在完成了。试试它的工作原理...
【讨论】:
我知道这有点老了 - 但当我在寻找类似的答案时,它出现在我的搜索中。您可以从以下页面获取代码以嵌入包含公共帖子、cmets 等(有点像 YouTube 嵌入)的 iframe:https://developers.facebook.com/docs/plugins/embedded-posts/ 使用社交插件。不过,我认为 Facebook 永远不会允许您对整个网站进行 iframe。
【讨论】:
我相信 facebook 是一个反框架脚本。它会检测它是否在 iframe 中并显示一个徽标,当您单击该徽标时,它会将您带出 iframe。也许他们有一个允许首先进行身份验证的 sdk,然后它将允许 iframe。我不知道。
【讨论】: