javascript: capturing load event on LINK
Posted
by pgn
on Stack Overflow
See other posts from Stack Overflow
or by pgn
Published on 2010-04-14T08:10:30Z
Indexed on
2010/04/14
8:13 UTC
Read the original article
Hit count: 307
javascript-events
|JavaScript
hello everyone,
i'm trying to attach an event handler to the load event of a link tag, to execute some code after a stylesheet has loaded.
new_element = document.createElement('link');
new_element.type = 'text/css';
new_element.rel = 'stylesheet';
new_element.href = 'http://domain.tld/file.css';
new_element.addEventListener('load', function() { alert('foo'); }, false);
document.getElementsByTagName('head')[0].appendChild(new_element)
i have tried onreadystatechange as well
new_element.onreadystatechange = function() { alert('foo'); }
unfortunately neither approach results in an alert being triggered.. Furthermore, new_element.onload is null after registering a handler for the 'load' event with addEventListener.. is that normal?
thanks, andrew
ps: i may not use any framework in solving this
© Stack Overflow or respective owner