Browse Source
From "[WHATWG HTML Living Standard] (https://html.spec.whatwg.org/multipage/indices.html#event-load)", the definition of 'onload': > Fired at the Window when the document has finished loading; fired at an element containing a resource (e.g. img, embed) when its resource has finished loading To adhere to that specification both handlers should be called as many times as Image loads. From Google Chrome's Developer Tools: ```js > function handler(evt) { console.log('img handler: %s', evt.type); } < undefined > var img = document.createElement('img') < undefined > img.onload = handler < handler(evt) > img.onerror = handler < handler(evt) > img.src = 'https://www.google.com/images/errors/logo_sm_2.png'; true < true < img handler: load > img.src = 'https://www.google.com/images/errors/logo_sm_2.png'; true < true < img handler: load > img.src = 'https://example.com/404.png'; true < true < img handler: error > img.src = 'https://example.com/404.png'; true < true < img handler: error ```v1.x
Raul Ochoa
10 years ago
2 changed files with 61 additions and 4 deletions
Loading…
Reference in new issue