JS in IE6 + IE7 fails 25% of the time

Hi folks,

I’ve got my site working in FF, Safari, and IE8, but I need some help getting it to work in IE7. I’m using the Prototype library, by the way. I suspect it has nothing to do with Prototype and more to do with how IE7 and 6 execute JS unpredictably.

To see the error, click the button. It will only happen about 25% of page loads, so reload the page if you don’t see it.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <script src="scripts/lib/prototype.js" type="text/javascript"></script>
        <script src="scripts/src/scriptaculous.js" type="text/javascript"></script>
        <script type="text/javascript">
            //<![CDATA[
            var MYAPP = {
                Class1: null,
                class1: null
            }
            
            MYAPP.Class1 = Class.create({
                initialize: function() {
                    this.myValue = 'my value';
                },
                speak: function() {
                    alert(this.myValue);
                }
            });
            
            Event.observe(window, 'load', function() {
                MYAPP.class1 = new MYAPP.Class1();
            });
            //]]>
        </script>
    </head>
    <body>
        <button onclick="MYAPP.class1.speak()" />make class1 speak</button>
    </body>
</html>