Stack Exchange sign up log in tour help stack overflow careers - TopicsExpress



          

Stack Exchange sign up log in tour help stack overflow careers Stack Overflow Questions Tags Users Badges Unanswered Ask Question Take the 2-minute tour × Stack Overflow is a question and answer site for professional and enthusiast programmers. Its 100% free, no registration required. Facebook Javascript SDK Problem: “FB is not defined” up vote 29 down vote favorite 4 The following code, copied from the Facebook documentation here, is not working for me in Chrome. FB.init({ appId : YOUR APP ID, status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML }); In the Javascript console I get: Uncaught ReferenceError: FB is not defined Im not having any problems with the SDK in Firefox or Safari, just Chrome. javascript google-chrome facebook facebook-javascript-sdk share|improve this question asked Dec 29 10 at 18:56 Alex Miller 3511311 possible duplicate of FB is not defined problem – ifaour Feb 21 12 at 6:46 check my answer in the dup question. – ifaour Feb 21 12 at 6:47 add a comment 17 Answers activeoldestvotes up vote 42 down vote accepted I saw a case where Chrome had installed WidgetBlock which was blocking the Facebook script. The result was exactly this error message. Make sure you disable any extensions that may interfere. share|improve this answer answered Feb 7 11 at 0:51 pbz 2,52252642 Thanks a million. My chrome synced the widgetblock extension from my home computer to the workplace. Fun bug. – Kit Sunde Jul 1 11 at 5:09 5 FYI - this chrome extension also caused the problem - Facebook Disconnect - chrome.google/webstore/detail/… – Jody Feb 29 12 at 16:05 6 Ah, I was using Facebook Disconnect – Alex Miller Mar 31 12 at 2:33 1 Disconnect was the problem for me. – Søren Beck Jensen Apr 9 13 at 13:39 1 Disconnect for me also was the problem! – Clint C. Jun 27 at 15:27 show 3 more comments up vote 34 down vote So the issue is actually that you are not waiting for the init to complete. This will cause random results. Here is what I use. window.fbAsyncInit = function () { FB.init({ appId: your-app-id, cookie: true, xfbml: true, oauth: true }); // *** here is my code *** if (typeof facebookInit == function) { facebookInit(); } }; (function(d){ var js, id = facebook-jssdk; if (d.getElementById(id)) {return;} js = d.createElement(script); js.id = id; js.async = true; js.src = //connect.facebook.net/en_US/all.js; d.getElementsByTagName(head)[0].appendChild(js); }(document)); This will ensure that once everything is loaded, the function facebookInit is available and executed. That way you dont have to duplicate the init code every time you want to use it. function facebookInit() { // do what you would like here } share|improve this answer edited 2 days ago pi. 6,37941934 answered Jan 27 12 at 1:00 Matty 47447 1 Thank you for this. Just saved me from having to use sync instead of async. +1 to you – Damien Keitel Feb 22 12 at 15:53 I actually had to remove the call to FB.init() to make the above snippet work. – ripper234 Aug 28 12 at 14:01 add a comment up vote 15 down vote This error will also appear if you omit the semicolon after the fbAsyncInit definition. window.fbAsyncInit = function() { FB.init({ appId: YOUR APP ID, status: true, cookie: true, xfbml: true }); //do stuff }; //
Posted on: Sat, 22 Nov 2014 11:50:39 +0000

Trending Topics



Recently Viewed Topics




© 2015