开发者

Check color CSS file... change colors jquery plugin

开发者 https://www.devze.com 2023-03-03 17:32 出处:网络
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?

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.

  1. have a hidden <div id="colorIndicator" style="display:none"></div>
  2. have a css rule in every color.css with a corresponding color #colorIndicator { color: #ff0000; }
  3. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号