本文介绍了Facebook SDK和rails 4 Turbolinks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难尝试将javascript Facebook SDK快速加载到我的rails 4应用程序中。有没有一个很好的方法来使它的工作正常与turbolinks?



如果我添加这个代码在我的JS应用程序资产。
由于turbolinks,它不能正常工作:

 < div id =fb-root>< / DIV> 
< script>
window.fbAsyncInit = function(){
// init FB JS SDK
FB.init({
appId:'YOUR_APP_ID',//应用程序信息中心的应用程序ID
channelUrl:'//WWW.YOUR_DOMAIN.COM/channel.html',// x-domain comms的通道文件
status:true,//检查Facebook登录状态
xfbml:true //寻找页面上的社交插件
});

//附加的初始化代码(如添加事件侦听器)在这里
};

//异步加载SDK
(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 =//connect.facebook.net/ en_US / all.js;
fjs.parentNode.insertBefore(js,fjs);
}(document,'script','facebook-jssdk'));
< / script>

谢谢

解决方案

您将在这里找到将Facebook SDK与Turbolinks集成的正确解决方案:




I'm having a hard time trying to load fast the javascript Facebook SDK into my rails 4 application. Is there a good way to make it work correctly with turbolinks?

if i add this code on my JS application assets.It's not working properly due to turbolinks:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'YOUR_APP_ID',                        // App ID from the app dashboard
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });

    // Additional initialization code such as adding Event Listeners goes here
  };

  // Load the SDK asynchronously
  (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 = "//connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

thanks

解决方案

You will find the proper solution for integrating the Facebook SDK with Turbolinks here :

http://reed.github.io/turbolinks-compatibility/facebook.html

这篇关于Facebook SDK和rails 4 Turbolinks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 19:01