Is there anyway to listen to the onload event for a <link>
element?
F.ex:
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'styles.css';
link.onload = link.onreadystatechange = function(e) {
console.log(e);
};
This works for <script>
elements, but not <link>
. Is there another way?
I just need to know when the styles in the external stylesheet has applied to the DOM.
Update:
Would it be an idea to inject a hidden <iframe>
, add the <link>
to the head and listen for the window.onload
event in the iframe? It should trigger when the css is loaded, but it might not guarantee that it's loaded in the top window...