在我的html中,我有2个外部档案。
externalCSSContents = [];
function getExternalCSSContents(){
var i, href;
for (i=0; i < document.styleSheets.length; i++)
{
href = document.styleSheets[i].href;
if (href != null)
{
$.ajax({
async: false,
url: href,
success: function (data) {
externalCSSContents.push(data);
}
});
}
}
}
getExternalCSSContents();
alert(externalCSSContents.length);
and this code is sometimes alerting 1 in firefox but permanently 2 in other browsers. What s wrong and how can i solve it?
[Edit] href sometimes = null in ff
[Edit2] I understood, sorry that I didn t mention about prefixfree.min.js attached. And with this library document.styleSheets[i].href was working in FireFox like in Chrome without it. ( document.styleSheets doesn t supported by Сhrome ). Thank you all for your answers and once more sorry for my inattentiveness.