Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  175] [ 1]  / answers: 1 / hits: 106260  / 13 Years ago, wed, march 16, 2011, 12:00:00

Sometimes I'm getting the FB is not defined issue when loading the http://connect.facebook.net/en_US/all.js



I've realized that the problem is because sometimes my website just doesn't load that file. So it gets nothing, and the object FB literally doesn't exist.



My solution is to prevent my users when this happens, so I've tried the following codes in JavaScript but none seems to work:



if (FB) {/*run the app*/} else {/*alert the user*/}
if (FB!==false) {/*run the app*/} else {/*alert the user*/}
if (FB!='undefined') {/*run the app*/} else {/*alert the user*/}


thanks for the answer!


More From » facebook

 Answers
30

Assuming FB is a variable containing the Facebook object, I'd try something like this:



if (typeof(FB) != 'undefined'
&& FB != null ) {
// run the app
} else {
// alert the user
}


In order to test that something is undefined in plain old JavaScript, you should use the typeof operator. The sample you show where you just compare it to the string 'undefined' will evaluate to false unless your FB object really does contain the string 'undefined'!



As an aside, you may wish to use various tools like Firebug (in Firefox) to see if you can work out why the Facebook file is not loading.


[#93241] Tuesday, March 15, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaylynkarinam

Total Points: 740
Total Questions: 103
Total Answers: 103

Location: Liechtenstein
Member since Wed, Dec 8, 2021
2 Years ago
;