garuda
garuda

Reputation: 67

how to add some kind of delay in javascript, race condition between href and onclick

the problem there seems to be a race condition between href and onclick in some browsers like chrome and ie9, so i wanted onclick to run first and then return to one button url, so i wrote the code

 function track_cb(link) {  
  Cancel();     
 //alert(window.location.href);
  return true;
   }

i modified href kind of like this

  <A HREF="some button url" onclick="return            
   track_cb(this);"

after cancel(), i need some time so that button url executes next, how to properly achieve this ?

Thanks in advance....

Upvotes: 0

Views: 356

Answers (1)

Kvothe
Kvothe

Reputation: 396

Remove the href attribute and at the end of the function insert a javascript command to go to the url. Use callback if the function takes a long time to execute (eg it retrieves something from another webpage/server).

Upvotes: 1

Related Questions