简体   繁体   中英

check if less file exists or not

I'm wondering if it is possible to check if a particular less file has called in the header section. If it is there, I'd like to perform some js action.

Do you know any solution how could I check this?

Thank you in advance!

if ($('head link[href$="yourFileName"]').length) {
    // ... (do your thing)
}

But as @LeoJavier suggests, you'd be looking for a .css file, not .less .

浏览器不会读取较少的文件,而是读取较少文件生成的css文件。

You can use normal jQuery or javascript selectors to access the link element and then do your logic based on if the href is the path to the file you are referencing.

For example javascript to select the link element and href:

var linkElement = document.getElementsByTagName("link");

var linkHref = linkElement.getAttribute("href");

Note: I assume you mean CSS file rather than LESS file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM