[removed] capturing load event on LINK

后端 未结 9 1322
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 01:00

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.createElem         


        
9条回答
  •  借酒劲吻你
    2020-11-29 01:46

    The link.innerHTML, link.styleSheet and cssRules are all good approaches, but they do not work for stylesheets that belong to a domain outside of the origin domain (so cross-site stylesheet loading fails). This can be pretty unexpected when a subdomain vs a domain is used (www for example) or a static CNS is used. And its pretty annoying since elements have no same-origin restriction.

    Here's a solution that that uses the onload method for browsers that support it (IE and Opera), but then uses a timed interval for browsers that do not and compares the ownerNode and owningElement nodes to check to see when the stylesheet has made its way into the DOM.

    http://www.yearofmoo.com/2011/03/cross-browser-stylesheet-preloading.html

提交回复
热议问题