我试图加载额外的css
文件中使用这样的代码:延迟加载
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/
这完美的CH,FF,歌剧20+等工作 ,
但它不工作在Safari5.1,IOS 5.1,Android 4.2及更少!
为什么onload/onerror
事件不适用于.css
文件?
p.s.如果我将文件更改为.js
- onload
或onerror
事件有效。
看看https://developer.mozilla.org/en/docs/Web/HTML/Element/link#Browser_compatibility - 看起来就是这样吧 –
@JaromandaX:我看到'?',而不是“不支持“,对于OP询问的...... –
显然MDN不知道 - 从上面的证据可以看出,它不被支持 - 而且我**知道当假设 –