Solved

Javascript function question : at start - at end

Posted on 2011-03-16
2
402 Views
Last Modified: 2012-05-11
Hi all,

I have a javascript function that opens a dialog and I need to add something at the beginning and also tell in to do something when the dialog ends or end of the function.

for example:

function myFunction() {
    alert('Here it all starts');
   FB.init({
      appId:'43243', cookie:true,
      status:true, xfbml:true
      });

      FB.ui({ method: 'apprequests',
      message: 'message here!'});
     }

     //Finally  
     alert('The End');
 
   
}
0
Comment
Question by:error77
2 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 35146756
And what's the problem?
0
 
LVL 5

Accepted Solution

by:
vks_vicky earned 500 total points
ID: 35146765
window.fbAsyncInit = function myFunction() {
    alert('Here it all starts');
   FB.init({
      appId:'43243', cookie:true,
      status:true, xfbml:true
      });

      FB.ui({ method: 'apprequests',
      message: 'message here!'});
     }

     //Finally  
     alert('The End');
   
}

function fbEnsureInit(callback) {
        if(!window.fbApiInit) {
            setTimeout(function() {fbEnsureInit(callback);}, 60);
        } else {
            if(callback) {
                callback();
            }
        }
    }

And the usage would be like

fbEnsureInit(function() {
    console.log("this will be executed once FB is initialized");
});

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now