sinini
sinini

Reputation: 1433

jquery, control order of how code is executed

Via PHP, i'm generating some JavaScript code, witch looks like this:

<script type="text/javascript"> 
  $(window).load(function() {
    maps.showUsers('Odenthal, Germany',1);
    maps.putCenter(51.1833,7.2);
  });
</script> 

I have to be sure, that the first line is executed before the second line. This works fine in IE and FF, but not in Chrome. How can i control it?

Upvotes: 1

Views: 896

Answers (2)

Jacek Kaniuk
Jacek Kaniuk

Reputation: 5229

try callbacks:

$(window).load(function() {
    maps.showUsers('Odenthal, Germany',1, function(){
        maps.putCenter(51.1833,7.2);
    });
});

you have to use that callback at the end of your function:

function showUsers(a, b, c, callback) {
    ...
    if(typeof callback == 'function')
        callback.call();
}

Upvotes: 2

ShankarSangoli
ShankarSangoli

Reputation: 69905

Try this with some delay. You can set the appropriate delay as per your need.

  $(window).load(function() {
    maps.showUsers('Odenthal, Germany',1);
    setTimeout(function(){
      maps.putCenter(51.1833,7.2);
    }, 400);
  });

Upvotes: 0

Related Questions