HTML - 如何有效地在一个页面上执行多个Facebook Like按钮 [英] HTML - How to efficiently do multiple Facebook Like buttons on one page

查看:437
本文介绍了HTML - 如何有效地在一个页面上执行多个Facebook Like按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我需要大约30个Facebook Like按钮。他们都喜欢相同的网址。基本上只需复制HTML代码到处都是。



无论如何,当您加载页面时,每个Facebook Like Button div都会向Facebook拨打电话。你可以在开发工具中看到它。



有没有更有效的解决方案来解决这个问题?

更新



让我再问一个问题:是否有任何方法将按钮等每个Facebook div动态连接到Facebook服务器上?所以基本上,当页面加载时,没有一个Facebook div与Facebook建立连接,并且脚本能够通过每个按钮并按需(按需)运行连接它的脚本。这可能吗?现在看来,它的工作方式是我的页面从Facebook下载 all.js 。该脚本查找页面上的所有Facebook div,并将它们连接到Facebook并将它们变为Like按钮。如果有一种方法可以选择性地在任何你想要的div上运行这个脚本,这将帮助我更接近解决方案...

经过多次测试,这是我的最终解决方案:



自动加载Facebook all.js SDK解析页面上的所有Facebook Like按钮。不幸的是没有选择加载SDK而没有解析现有的Facebook Like按钮。



两种解决方案:


  1. 加载SDK并且页面上没有任何Facebook Like按钮。然后,每当屏幕上出现一个Like按钮时,加载Like按钮html / fbxml,然后使用SDK分析标记。我没有对此进行测试。


  2. 完全不加载SDK。只需使用AJAX即可在需要加载的位置动态添加Facebook iframe。我去了这个解决方案。



I have a page where I need to have about 30 Facebook Like buttons. They all Like the same url. Basically just duplicate HTML code everywhere.

Anyways, when you load the page, every single Facebook Like Button div makes calls back and forth to Facebook. You can see it in the dev tools going back and forth. Slows down the page load a lot.

Is there a more efficient solution to this problem?

UPDATE

Let me ask an alternate question: Is there any way to dynamically connect each Facebook div like button to Facebook servers on demand? So basically, when the page loads, none of the Facebook div's make the connection to Facebook and a script is able to go through each button and (on demand) run the script that connects it. Is this possible? Right now, it appears that the way it works is that my page downloads the all.js from Facebook. This script finds all facebook div's on the page and connects them to Facebook and makes them into Like buttons. If there was a way to run this script selectively on any div you wanted to, that would help me get closer to a solution...

解决方案

After much testing, this was my final solution:

Loading the Facebook all.js SDK automatically parses all Facebook Like buttons on the page. There is unfortunately no option to load the SDK without parsing existing Facebook Like buttons.

Two solutions:

  1. Load the SDK and not have any Facebook Like buttons on your page. Then, whenever there is a Like button that is visible on the screen, load in the Like button html/fbxml and then parse the markup using the SDK. I did not test this.

  2. Don't load the SDK at all. Simply use AJAX to dynamically add a Facebook iframe in wherever you want to load one up. I went with this solution.

这篇关于HTML - 如何有效地在一个页面上执行多个Facebook Like按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆