Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actualy, there's a better solution.</p> <p>There are 2 things that you could do better:</p> <ol> <li>In your <code>FB.init</code> method, you're setting <code>status: true</code>. This tells the page that it should check whether the user is logged in the facebook immediately after page loads. In your case, it's not only that you don't need it - it will take some of your visitor's bandwidth for round trip to facebook that you don't actually need.</li> <li>You don't need to remember uid and accessToken variables since you can get them on demand by using <code>FB.getLoginStatus</code> method.</li> </ol> <p>The complete solution based on your sample code would be:</p> <pre><code>&lt;div id="fb-root"&gt;&lt;/div&gt; &lt;script&gt; window.fbAsyncInit = function() { FB.init({ appId : 'YOUR APP ID', status : false, cookie : true, xfbml : true }); }; (function(d){ var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); }(document)); function Facebook_login () { FB.getLoginStatus(function(response) { if (response.status === 'connected') { var uid = response.authResponse.userID; var accessToken = response.authResponse.accessToken; if ((parseFloat(uid) == parseInt(uid)) &amp;&amp; !isNaN(uid)) { $.ajax({ url: '/user_actions/prep_facebook_registration', cache: false, type: 'POST', data: { 'uid': uid, 'token': accessToken }, dataType: 'json', success: function(data) { if (data.success=='true') { if ((typeof(data.redirect) != 'undefined')) { if (data.redirect=='current') { location.reload(); } else { window.location=data.redirect; } } } } }); } } } } &lt;/script&gt; &lt;div class="fb-login-button" onlogin="Facebook_login()" autologoutlink="true" [parameters]&gt;&lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload