javascript - With JQueryMobile, Facebook JS SDK doesn't work after change page -


i have webapp works jquery mobile (full ajax navigation). initialize facebook sdk @ jquerymobile's pageinit event (each page called).

jquery(document).on('pageinit', function (event) {     // load fb sdk     window.fbasyncinit = function() {         fb.init({             appid      : 'myappid',             channelurl : '//url/channel.html',             status     : true,             xfbml      : true,             oauth      : true         });         fb.event.subscribe('auth.authresponsechange', getcurrentuser);     };     (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/all.js";         fjs.parentnode.insertbefore(js, fjs);      }(document, 'script', 'facebook-jssdk'));      // bind button current user manually     $('.findme').off('click');     $('.findme').on('click', getcurrentuser); }); function getcurrentuser(response) {     fb.api("/me", function (response) {         if (window.console && window.console.log) console.log(response.name);     }); } 

and html contains

<button class="findme">click infos me</button> 

this code works on first page. change page (ajax call), doesn't work on second page. reload (f5) second page, works.

have ever seen problem? have idea?

if use ajax change pages, don't have (and shouldn't) reinitialize fb sdk every time. also, you're loading asynchronously, doesn't need wait pageinit, you'll need bind click event inside window.fbasyncinit function. function runs fb sdk loaded.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -