Solved

Javascript function question : at start - at end

Posted on 2011-03-16
2
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

707 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