views:

100

answers:

1

I created an app which publishes to the user's wall. The problem is, the first time the user accesses the page, the FB.ui doesn't show up. After one reload, it works perfectly.

by first time, I mean when the user gives permissions to the app, OR when he has already given permissions. In both scenarios, the problem occurs. Any ideas, people?

FB.init({
  appId  : "XXXX",
  status : true,
  xfbml  : true,
  cookie : true
});
FB.ui(
{
 method: 'stream.publish',
 message: 'test message'
      }
);
A: 

This is a frequent problem in JS, with things like trying to calculate how far an item has moved, and it only starts counting after the first iteration.

You need to wrap your js in window.onload = function() {

}

Although this is buggy cross-browser, and may not fix issue. Have you heard of jQuery, its:

$(document).ready(function() {
}

If a very robust solution to ths problem

Liam Bailey
I've already tried jQuery, and tried wrapping the code in $(document).ready as well as $(window).load, but to no effect. The problem still occurs.
Dheeraj Kumar
All raw js code in the head of the page will load before the page is loaded. Can you implement it in this way?
Liam Bailey