Firefox automatically launches javascript function named 'onload'

Can someone confirm that firefox (3.6) automatically runs a javascript function called "onload" without an explicit call? Chrome and IE do not automatically run the declared function if they are not called, but firefox will apparently run the declared "onload" function even if it is not called (all in lower case).

Below is the jsfiddle link.

In the body tag, if you assigned a function called 'test' for the onload event, then firefox will call the test function. If you remove the onload call, firefox will automatically call the onload function.

Is this a famous property of firefox?

+4
source share
2 answers

Firefox 3.6 really does this. So do 4-8. Firefox 9 fixes this error so that function onload() {} no longer adds a function as a listener for load events. See https://bugzilla.mozilla.org/show_bug.cgi?id=659350 for more details on this change.

+3
source

This is because if you declare a global function onload() , it is actually window.onload . This example explains this:

 <script> var a = 1; alert(window.a); // alerts "1" </script> 

This should be valid for a cross browser (I tested it only on FF3.6 and IE7.8).

+3
source

All Articles