本文介绍了检测< link>资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览器为 / code>在我的情况下不可行。

Unfortunately, I think using a sentinel style and detecting load from a computedStyle isn't workable in my situation.

推荐答案

可能有更简单的方法,

There may be a simpler way to do it, but this worked for me.

请确保您的< link> 标记有 属性:

Make sure your <link> tag has a title attribute:

<link title="myStyles" rel="stylesheet" href="style.css" />

然后使用这样的函数检查特定样式集中是否存在样式: p>

Then use a function like this to check for the presence of a style within a particular styleseet:

function linkLoaded(linkTitle, checkStyle)
{
    for (var ix=0; ix<document.styleSheets.length; ix++) {
        try {
            if (document.styleSheets[ix].title == linkTitle) {
                var mySheet=document.styleSheets[ix];
                var myRules = mySheet.cssRules? mySheet.cssRules: mySheet.rules
                for (var jx=0; jx<myRules.length; jx++) {
                    var thisSelector = myRules[jx].selectorText.toLowerCase();
                    if (thisSelector.substring(0, checkStyle.length) == checkStyle) {
                        alert("Found style!");
                        return;
                    }
                }
            }
        }
        catch (err) {}
    }

    alert("Not loaded!");
    return;
}

这篇关于检测&lt; link&gt;资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:19
查看更多