Is it possible to check with JavaScript (jQuery) if there is a certain CSS file? And if there is that it loads a color array for jQuery plot?
Exa开发者_Python百科mple:
- I include a color CSS file (blue.css).
- Javascript will check if there is a color CSS file (blue.css, red.css, grey.css).
- There is blue.css in the page and the array colors for that CSS file ... is load for jQuery plot.
I would use the following approach.
- have a hidden
<div id="colorIndicator" style="display:none"></div>
- have a css rule in every color.css with a corresponding color
#colorIndicator { color: #ff0000; }
- On load make an ajax call to the server and get your colors
This could be the JavaScript using jQuery
$(function() {
$.ajax( {
method: 'POST',
url: '/give/me/colors',
data: { color: $('#colorIndicator').css('color'); },
dataType: 'json',
success: function(data) {
// handle your json data
}
});
});
Sounds a lot like this q/a will help:
HOW TO check if an external (cross-domain) CSS file is loaded using Javascript
精彩评论