Fixing IE8 mystery error KB927917

While testing some updates to one of our Facebook applications today, I ran into an odd error message on IE8.  The error message mentioned KB927917, and is caused by trying to modify the DOM before it is built.  At first, I was confused, because the app is not modifying the DOM at all, its a redirect that is part of the authentication step.  The culprit code was something like:

{syntaxhighlighter brush:js;}<script type=”text/javascript”>
top.location.href = ‘http://example.com/foo/’;
</script>

This was working, without warnings, in Chrome, Firefox, and IE7.  To prevent IE8 from complaining, the redirect should happen after the page is done loading.

{syntaxhighlighter brush:js;}<script type=”text/javascript”>
window.onload = function() {
top.location.href = ‘http://example.com/foo/’;
};

</script>