Follow-up code after the CSS has finished loading

Source: Internet
Author: User

Recently in the framework of writing the project, write a Jquerymessagebox class to use dialog () in the jquery UI to display the message box, in order to make the method convenient to call, then added the automatic Judgment page joins the Ui.js and Ui.css, the code is as follows:

[JavaScript]View Plaincopyprint?
  1. If the ui.js is not included, the reference
  2. if ($ (' script[src$= "" "Jquery-ui-1.8.11.custom.min.js" "]"). Length = = 0) {{
  3. $ ("" <script src='/js/jquery-ui-1.8.11.custom.min.js ' type=' text/javascript '/> '). AppendTo (  ' head ');
  4. }}
  5. If the CSS is not loaded, the load
  6. if ($ (' link[ref$= "" "Jquery-ui-1.8.14.custom.css" "]"). Length = = 0) {{
  7. $ (' <link href= ' ""/css/jquery-ui-1.8.14.custom.css "" rel= "" Stylesheet "" type= "" Text/css ""/> "). AppendTo (  ' head ');
  8. Dialog () script
  9. }}

But the CSS code will not be loaded immediately, so when the display dialog will not have the style (under IE9, because in the IE9 under the CSS even after downloading, will also redraw the page elements, and IE8 will not). To solve this problem, you can use Ajax, when the CSS is loaded, and then display dialog, so that you can show the style, the code is as follows:

[JavaScript]View Plaincopyprint?
  1. if ($ (' link[ref$= "" "Jquery-ui-1.8.14.custom.css" "]"). Length = = 0) {
  2. $.ajax ({
  3. URL: '/css/jquery-ui-1.8.14.custom.css ',
  4. Success: function (data) {
  5. //Create a STYLE element and append it to the head
  6. //Replace the path where images
  7. $ (' <style type= ' text/css ' > ' + data.replace (/url\ (images/g, ' url (/css/images ') + ' </style> ').  AppendTo (' head ');
  8. //dialog () script;
  9. }
  10. });
  11. }
  12. else {
  13. //dialog () script;
  14. }

Follow-up code after the CSS has finished loading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.