Solved

Javascript function question : at start - at end

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tiny glitch in my main slider 3 39
Html form and modal / img src -problem 3 30
Binding a Grid in Javascript 5 43
How to make google charts responsive 4 6
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

828 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