Fixing unknown runtime error in javascript

I’ve come across it so many times, and each time I forget. So in addition to a tidbit, this is also a note to myself.

How many times has it happened that you’ve been programming, working with Firefox, Chrome or Safari and everything works fine until… you open up  your page in Internet Explorer and you see that awful “unknown runtime error” .

First thing to check if you’re using ajax and trying to set innerHtml is that there are no html syntax errors.

But it can also happen without any ajax, and 9 times out of 10 it turns out the script that’s giving the error needs a delay. You can easily find out by putting an alert() somewhere at the beginning of the script. If it then works, it means you need a delay, which you can obtain using the setTimeout() function.

Here’s a link with information on that function: http://www.w3schools.com/js/js_timing.asp

October 16th, 2012 by