Friday 6 June 2008

Learning Log 2: Javascript + setTimeout

I found through trial and error that it is essential to enclose the function argument in the setTimeout method in quotes '' otherwise you get a javascript runtime error.

Also, I learnt that setTimeout doesn't actually halt execution, it just runs the specified code after a period of time, and keeps on executing as normal until then.

So, if you have the onclick event of a ASP.Net button/link set to perform some setTimeout functionality, it may not work, as the runtime will continue executing thus more than likely performing the PostBack before the time you specify in setTimeout is up...so your code never gets run!

www.sean.co.uk There is a nice post of a quick little wait() function which will halt execution if you absolutley have to...although this is seen as a bit of a no-no!

No comments:

Post a Comment