I'm trying to load additional css file using code like this:
var doc = document,
head = doc.getElementsByTagName('head')[0],
link = doc.createElement('link'),
file = link.cloneNode(true);
file.type = 'text/css';
file.rel = 'stylesheet';
file.onload = function () {
alert('css file is loaded!');
};
file.onerror = function () {
// 404 error
alert('Script ' + url + ' wasn\'t loaded! Check file URL');
};
file.href = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css';
head.appendChild(file);
http://jsfiddle.net/d3bcp4dy/1/
It's perfectly works in CH, FF, Opera 20+, etc.,
but it doesn't work in Safari5.1, IOS 5.1, Android 4.2 and less!
Why onload/onerror events don't work for .css file?
p.s. If I change file to .js - onload or onerror event works.
?, not "not supported," for the ones the OP is asking about...https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.cssis CORS enabled, so you can use XMLHttpRequest, or even, fetch (polyfills for fetch and Promise available for internet exploder) to load the css, and stick it in a <style> tag