Preliminary .css file - Firefox vs IE

I found IE has different behavior against Firefox when I use this

$ ('head') PREPEND ('') ;.

It's basically just for adding topic-2.css on top in the HEAD tag (for topic purposes). I do this because I don't want it to load because I am using csspreload http://www.filamentgroup.com/lab/update_automatically_preload_images_from_css_with_jquery/

In Firefox, the file with the .css extension at the top will be moved to the file priority below. This works great!

In IE, a new .css file added later to HEAD takes effect. It doesn't matter if it's above or below.

  • How do I fix this behavior for IE?
  • Is there another image loader that I can inject .css files into the options and it loads from there? The current file should see the .css file in the link inside the html.

thank

+2


source to share


2 answers


I don't quite understand what you are trying to do here: are you trying to add the stylesheet to the page dynamically without affecting it in order to preload its images?

If so, this snippet may be needed:

$('link[rel="stylesheet"][href="theme-2.css"]').attr('disabled', 'disabled');



This will disable the stylesheet, but it will remain loaded. If you want to enable it in the future, you can do this:

$('link[rel="stylesheet"][href="theme-2.css"]').removeAttr('disabled');

Edit: What you really want, I suppose, is the functionality from the attribute disabled

. You can actually set this when you add this stylesheet and it won't be applied to the page. The snippets above show you how to do this dynamically.

+2


source


First of all, there is probably no way to successfully do what you want in Internet Explorer. Unless in IE you added no existing stylesheets after loading said stylesheet.

Second, why not just modify an existing plugin?

Call the following address:

$.preloadCssImages({extra: [{href: "/css/styles.css"}]});

      

Or, if you have some additional CSS files:



$.preloadCssImages({extra: [{href: "/css/styles.css"}, {href: "/css/styles2.css"}]});

      

Etc.

Then, after the line "parseCSS (document.styleSheets)" at the bottom of the file, paste:

if (settings.extra)
{
    parseCSS(settings.extra);
}

      

Easy peasy.

0


source







All Articles