How to workaround 'FB is not defined'?

前端 未结 12 1253
余生分开走
余生分开走 2020-12-04 17:56

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 sometime

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 18:45

    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.

提交回复
热议问题