English 中文(简体)
外壳,Jajax, 火灾fox, jquery 。
原标题:external css, $.ajax, firefox, jquery .

在我的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.

问题回答

另一名阿富汗复兴共和军受害者。 AJAX支持Asynchronousalle Java和XML。 第一部分已在这里(Asynchronous )。

或许,在发出警报之前,AJAX号呼吁尚未结束。 当你完成AJAX的职能时,你可以使用一个叫.。

externalCSSContents = [];

function getExternalCSSContents(callback){
    var i, href;
    for (i=0; i < document.styleSheets.length; i++)
    {
        href = document.styleSheets[i].href;
            if (href != null)
            {  
                $.ajax({
                    url: href, 
                    success: function (data) { 
                        externalCSSContents.push(data);
                        callback();
                    }
                });
            }
    }

}
getExternalCSSContents(downloadReady);

function downloadReady() {
    alert(externalCSSContents.length);
}

如果把警示转向成功功能,你可能会有种族条件。 你们要警惕,等待阿盟教团的呼吁结束。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签