【问题标题】:Embed Facebook page into site将 Facebook 页面嵌入网站
【发布时间】:2018-03-25 19:00:57
【问题描述】:

回到另一个问题,但这次与 SQL 无关!!

我正在创建一个允许用户注册和发布帖子的网站。当他们注册时,他们可以输入 Facebook 页面名称,我希望能够将该页面嵌入到他们的个人资料页面中,这样当人们查看他们的个人资料时,Facebook 页面将显示在一个小窗口中。我去了 Facebook 的 Page Plugin 页面,但我不确定这是实现我想要的最佳方式。我做了很多搜索,但没有任何运气。

我尝试在网站中只放置一个页面的代码,但它总是出现空白。这是我从页面插件网站得到的:

<div id="fb-root"></div>
    <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.12';
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-page" data-href="https://www.facebook.com/KeenesListcom-126649220715963/" data-tabs="timeline" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"><blockquote cite="https://www.facebook.com/KeenesListcom-126649220715963/" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/KeenesListcom-126649220715963/">KeenesList.com</a></blockquote></div>

感谢任何帮助。

编辑

好的,所以问题实际上出在 Google Chrome 上。我在 IE 11 和 Firefox 中尝试过,页面加载正常。仍然需要弄清楚为什么它没有在 Chrome 中加载。

第二次编辑

好的,这很奇怪。我使用 iframe 显示了 3 个不同的项目。 Facebook 页面、Strava 活动日志和 Trailforks 活动日志。 Strava 和 Trailforks 项目显示正常,但 Facebook 页面出于某种原因却没有。这仅在 Chrome 中,Facebook 在 Firefox 和 IE 中运行良好。这是我的代码:

<iframe src=https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Fmountainbikingintheus%2F&tabs=timeline&width=350&height=400&small_header=false&adapt_container_width=true&hide_cover=false&show_facepile=true&appId width=350 height=400 style=border:none;overflow:hidden scrolling=no frameborder=0 allowTransparency=true></iframe>

<iframe height=160 width=300 frameborder=0 allowtransparency=true scrolling=no src=https://www.strava.com/athletes/21039441/activity-summary/947ebf6e987358db8c8785041ad46b5a4d4ea7c5></iframe>

<iframe width=400 height=277 frameborder=0 src=https://www.trailforks.com/widgets/ridelogs/?userid=1306231&w=400px&h=277px&map=0&stats=1></iframe>

第三次编辑:完整代码

这是我的完整代码。我将页面剥离到最低限度,但仍然遇到问题。我尝试了多台计算机,但在 Firefox 和 IE 中工作时,它仍然无法在 Chrome 中显示。

<html>
    <head>
        <title>Test IFrame</title>
    </head>
    <body>
        <iframe src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Fmountainbikingintheus%2F&amp;tabs=timeline&amp;width=350&amp;height=400&amp;small_header=false&amp;adapt_container_width=true&amp;hide_cover=false&amp;show_facepile=true&amp;appId" width="350" height="400" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>
    </body>
</html>

【问题讨论】:

    标签: php facebook iframe plugins


    【解决方案1】:

    您所有的 HTML 都是无效的。至少,您需要将属性值放在引号中。您还应该将任何保留的实体(如 &amp;amp;)转义为 &amp;amp;

    <iframe src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Fmountainbikingintheus%2F&amp;tabs=timeline&amp;width=350&amp;height=400&amp;small_header=false&amp;adapt_container_width=true&amp;hide_cover=false&amp;show_facepile=true&amp;appId" width="350" height="400" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>
    
    <iframe height="160" width="300" frameborder="0" allowtransparency="true" scrolling="no" src="https://www.strava.com/athletes/21039441/activity-summary/947ebf6e987358db8c8785041ad46b5a4d4ea7c5"></iframe>
    
    <iframe width="400" height="277" frameborder="0" src="https://www.trailforks.com/widgets/ridelogs/?userid=1306231&amp;w=400px&amp;h=277px&amp;map=0&amp;stats=1"></iframe>
    

    【讨论】:

    • 感谢您的回复。我已经尝试过两种方式,有引号和没有引号。无论哪种方式,它都不会在 Chrome 中显示,但在 IE 和 Firefox 中可以正常工作。
    • @DarthMikeyD 您的问题可能与您的 HTML 的其余部分有关,因为我在这个答案中测试了代码并且它工作正常。 jsfiddle.net/0eacdwgo
    【解决方案2】:

    好吧,我是个白痴。我在 3 台不同的计算机上尝试了 Chrome,结果相同。我碰巧瞥了一眼右上角,看到我的广告拦截器阻止了一些东西,而 iframe 是页面上唯一的项目。所以,我关闭了广告拦截器并重新加载了页面,它工作正常。所以,必须想办法解决这个问题。

    【讨论】:

      猜你喜欢
      • 2011-12-18
      • 2010-09-18
      • 1970-01-01
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 2019-02-09
      • 2023-03-25
      相关资源
      最近更新 更多