facebook javascript sdk - FB is not defined error in Cordova/Ionic App -
i aware receiving following error common problem:
referenceerror:fb not defined
i have referenced following post seems cover wide array of solutions. fb not defined problem
the problem having if test out app deploying browser, fbasyncinit(...) hit in root index.html page.i know because put alert('fbasyncinit(..)') on first line of fb init code. example, if run following command, alerts fbasyncinit(..)
ionic serve
as deploy device using following command, no alert , when try invoke $cordovafacebook.login(...) gives me following error:
referenceerror: fb not defined
my root index.html looks similar (removed stuff brevity).
<html> <!-- other stuff here --> <div id="fb-root"></div> <script type="text/javascript" src="lib/additional/facebookconnectplugin.js"></script> <script> window.fbasyncinit = function() { console.log('fbasyncinit(..)'); fb.init({ appid : '/*app id here*/', cookie : true, // enable cookies allow server access xfbml : true, // parse social plugins on page version : 'v2.1' // use version 2.1 }); (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/sdk.js"; fjs.parentnode.insertbefore(js, fjs); }(document, 'script', 'facebook-jssdk')); }; </script> <!-- other stuff here --> </html> the 1 thing hitting following piece of code defined in facebookconnectplugin.js
// bake in js sdk (function () { if (!window.fb) { console.log("launching fb sdk"); var e = document.createelement('script'); e.src = document.location.protocol + '//connect.facebook.net/en_us/sdk.js'; e.async = true; document.getelementbyid('fb-root').appendchild(e); console.log(window.fb) //fb undefined } }()); when script tag loads facebookconnectplugin.js , piece of code runs, attempts print window.fb console, undefined.
any idea wrong given code above?
have tried surround script document ready ?
document.addeventlistener("domcontentloaded", function(event) { //do work }); moreover, not recommand perform action that.
you shall :
- define controller on app
- add $ionicplatform ready event controller
- perform initialisation of fb plugin in it.
Comments
Post a Comment