Bug Tracker

Ticket #12145 (closed bug: patchwelcome)

Opened 2 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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/

Change History

comment:1 Changed 2 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to patchwelcome

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.

Note: See TracTickets for help on using tickets.