Is there a plugin or feature in jQuery that enables the dynamic loading of stylesheets from different origins similar to开发者_如何学Python $.getJSON() or $.getScript()? I am able to dynamically integrate a style sheet from the same origin, but I need to be able to dynamically inject a jQuery UI theme from a different origin into a page. I guess I can load the CSS file as JSON data and then apply the contents using $().css(); however, I was looking for a more elegant solution.
Thanks
If you need the browser to notify you when the CSS is loaded into the browser, then I suggest to use the JSON solution as browsers don't notify the script when CSS files are loaded.
Otherwise, just go ahead and load the external CSS file by dynamically creating a <style>
tag which you will need to attach to the document <head>
. Unlike loading JavaScript from an external domains, browsers don't impose any restrictions over loading CSS files from other domains.
精彩评论