Even though both do the samething, i just want to know is there any specific advantage using one over another?
Event.observe(window, "load", function(){
//do something
});
window.onload = function(){
//do something
}
                The difference is that window.onload is defined in the DOM Level 0 Event Model and will erase all earlier registed events. It's an 'native' call from an old API.
The Event.observe from the prototype javascript framework will determine the best event attacher available. A facade pattern. In modern browsers, the addEventListener will be called - attachEvent in case of Internet Explorer below version 9. In old browsers the onload will be called.
It obvious that a facade will choose the best option available, like Event.observe for prototype or .load in case of jQuery for example.
The methods from the DOM Level 2 Event Model are preferred over the DOM Level 0 Event Model methods because they act as observers and don't erase previous handlers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With