Solved

Javascript function question : at start - at end

Posted on 2011-03-16
2
404 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

803 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