DevHints

Archive for the ‘Internet Explorer’ Category

There’s been this long standing bug with IE and changing the src attribute to update the image. Under certain conditions, it causes the image to simply disappear. There are two well known solutions to this problem:

1.) Have an alert box popup immediately after the change.

2.) Use a setTimeout function.

Neither of these is exactly pretty. But fear not, there’s a new way to do this that’s really ingenious. Are you ready for it? Here it is in an example:

var src=”http://example.com/image.gif”;
document.getElementById(‘myimage’).src = src;
return false;

Did you catch that? Just add “return false;” immediately after the update to the image src! Hopefully this will save you an entire day of frustration. 😉