Prototype: 'Event.observe(window, 'load', function()...' not working in IE 6/7


#1

I can't get this function to work in IE 6 / 7 (it works fine in Firefox)...

<script type="text/javascript">
Event.observe(window, 'load', function() {
	alert("Loaded!");

	// some more code down here, but even without it it doesn't work!
});
</script>

I'm fairly new to Prototype, am I missing something? I've found several posts on other forums where people have come across the same problem - but in their wisdom they found the solution out themselves but didn't bother to post the answer!

Thanks in advance


#2

Should work just fine - this does:

<html>
<head>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript">
Event.observe(window, 'load', function() {
    alert("Loaded!");
 
    // some more code down here, but even without it it doesn't work!
}); 	
</script>
</head>
<body>
stuff
</body>
</html>


#3

Thanks for looking into this jim

Ended up going through it removing code line by line. In hindsight I probably should have posted all of the code.

The reason it wasn't working in IE was because I used 'class' as a variable name somewhere else on the page - must be a reserved word or something? Funny how it worked in Firefox though.


#4

Yep it's a reserved word:
http://javascript.about.com/library/blreserved.htm


#5

Consider that page bookmarked! Could save me a few hours of hair tearing... thanks again Jim.


closed #6