0

I need to check the preticular css file is loaded or not in the current page using javascript.

Suggest any idea to find this using javascript.

2

1. CSS says: Hello I was (not) loaded

If you have control over how the CSS is loaded you can add events

This extract from my Fabric Iconator checks if the file was not loaded

<link rel="stylesheet" type="text/css" 
      id="FabricCore601"
      onerror="disableMissingFabricCore(this);"
      href="//spoprod-a.akamaihd.net/files/fabric/office-ui-fabric-core/6.0.1/css/fabric.min.css">
</link>

So you can add the onload (for a succesful load) event and track whatever you need to track

2. Hello CSS, are you a DOM element?

LINK and STYLE tags are DOM elements, so like any element you can check if they exist

var myCSS=document.querySelector("link[href*='6.0.1']")

will return undefined if it doesn't exist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.