javascript - many facebook like buttons on a page, asynchronously -


i'm building wall of people who've written messages on our site. each message, want include facebook button. facebook's implementation include script tag before building fb:like tag.

 <script src="http://connect.facebook.net/en_us/all.js#xfbml=1"></script>       <fb:like href="http://example.com/messagewall.aspx/fan/222"              show_faces="false" width="250">  </fb:like> 

i tried approach, because i'm showing 121 people on page @ time, page performance is, shall say, sub-par. can't believe have include script tag each time.

i'm trying now, implement asynchronous way of doing this.

i've tried this:

    (function() {         var e = document.createelement('script'); e.async = true;         e.src = document.location.protocol + '//connect.facebook.net/en_us/all.js#xfbml=1';             var s = document.getelementsbytagname('script')[0]; s.parentnode.insertbefore(e, s);     }());      var firsthalfoflikebutton = '<fb:like href="http://example.com/messagewall.aspx/fan/';     var secondhalfoflikebutton = '" layout="button_count" show_faces="false" width="250"></fb:like>';     var userid, divid;     (var x=0; x<listofidsofactivetiles.length; x++) {         userid = listofidsofactivetiles[x][0];         divid= listofidsofactivetiles[x][1];         $("div#" + divid+ " .hbo-message").append(firsthalfoflikebutton + userid + secondhalfoflikebutton);     } 

i tried asynchronously attach all.js fb-root before looping through , attaching fb:like tag each location.

 (function() {     var e = document.createelement('script'); e.async = true;      e.src = document.location.protocol + '//connect.facebook.net/en_us/all.js#xfbml=1';          document.getelementbyid('fb-root').appendchild(e);  }()); 

i tried looping through , creating fb:like tag, , attaching all.js file.

update: in each instance, can see <fb:like... tag created, facebook all.js never goes out , builds button, if load @ first load.

does have ideas?

thanks, scott

update

returning page, way after fact, ended doing dynamically build button each person's image upon click of item. so, onclick code checks see if it's not there, , if not, builds using building blocks have above.

this way, don't have create 121 buttons upon page load. instead, create them on-demand.

you can see finished project @ honeybunchesofoats.com

you need include facebook script once, not once each button.. search through page xfbml elements.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -