Product Development in Brisbane

JavaScript hacking

Well… this isn’t quite java but should be interesting for the web developers out there.

When doing a bunch of img.src calls just before changing a div from invisible to visible, the images don’t get displayed properly (on some clients when the wind blows in the wrong direction).

This is after having to go to the pain of setting the img.src’s in the first place because of a bug on a different version of ie :(.

So before changing the div display attribute I have to do a sleep.

In a real language this would be a call to Thread.sleep or similar. JavaScript has a funky setTimeout method (this takes a string method to call so state can’t be passed in), but doesn’t support my usage because state is required.

Google led me to Guy’s World, who linked to a great article titled How do I pause execution in JavaScript?

The window.ShowModalDialog hack (I would use a different word but nothing but hack meets the requirements) discussed in the article is how I have got this working. Another ugly DHTML hack required to get things working in Microsoft land.

Leave a Reply