Skip to main content

Bug Tracker

Side navigation

#12145 closed bug (patchwelcome)

Opened July 25, 2012 03:15PM UTC

Closed August 21, 2012 02:37AM UTC

adding a new css file using a relative url does not work in IE8 on Windows XP

Reported by: maspetsberger Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Description

I added a new, relative css link using jQuery in the following way:

var style = jQuery("<link rel='stylesheet' type='text/css' href='style.css' />");
jQuery("head").append(style);

As far as I can tell, this works as expected on most browsers.

However, in IE8 and Windows XP, it doesn't.

It works fine in IE8 browser mode of an IE9 on Windows 7, I can't tell whether a real IE8 on Windows 7 has the problem.

If I use an absolute url, like ''http://jQuery.com/style.css'', it works for that specific file, i.e. style.css, yet it does not work for those files that are included through ''@import'' within it.

When I use the native way to add the styles, everything is fine:

var style = document.createElement("link");
style.setAttribute("type", "text/css");
style.setAttribute("rel", "stylesheet");
style.setAttribute("href", "style.css");
jQuery("head")[0].appendChild(style);

This bug is similar to http://bugs.jquery.com/ticket/7522, which unfortunatly was closed.

The snippet reported there is still valid though:

http://jsfiddle.net/vs5NC/16/

This snippet, which uses the native way of adding, should work fine:

http://jsfiddle.net/CNEsE/

Attachments (0)
Change History (1)

Changed August 21, 2012 02:37AM UTC by dmethvin comment:1

resolution: → patchwelcome
status: newclosed

The problem appears to be that IE does not like trying to process the relative URL without knowing the base address of the page where it isn't yet placed. This hybrid works fine in IE8:

http://jsfiddle.net/vs5NC/21/

I don't think this can be fixed inside jQuery, it's an HTML serialization issue, but I'll mark it patchwelcome.