Posts filed under 'Uncategorized'

IE7 Bug, dynamically loaded css files including @import fails to load imports

Consider the following scenario:

- html page: 
  - head
      <link type="text/css" rel="stylesheet" media="all" href="css/red.css" id="cssLink"/>
  - script
      function changeRed() {		
		var cssFile = document.getElementById('cssLink');
		if( cssFile ) {
			cssFile.href = 'css/red.css';	
		}
      }

      function changeBlue() {		
		var cssFile = document.getElementById('cssLink');
		if( cssFile ) {
			cssFile.href = 'css/blue.css';	
		}
      }
  - body
  	<div id="testZone">
	<div id="red">
		<h1>This should be red</h1>
 		<p>"Cogito ergo sum"</p>		
 	</div>	
 	<div id="blue">
		<h1>This should be blue</h1>
 		<p>"Cogito ergo sum"</p>		
 	</div>
	</div>

And the following css files:

- red.css


@import url(redminor.css);
div#testZone {
	background-color:white;
	margin: 20px;
	border:3px solid red;
	padding:20px;	
}

- redminor.css


div#red { display:block;}
#red h1 { color:red; }
#red p { color: red;}

div#blue { display: none;}

- blue.css


@import url(blueminor.css);
div#testZone {
	background-color:white;
	margin: 20px;
	border:3px solid blue;
	padding:20px;	
}

- blueminor.css


div#blue { display:block;}
#blue h1 { color:blue; }
#blue p { color: blue;}

div#red { display: none;}

At page load the red css is applied by default, which works as expected in all browsers.

When the changeRed() or changeBlue() functions are invoked, the behavior is the expected one in: IE6, FF 1.5-20, Opera 9, but in IE7 only the blue.css or red.css rules get’s applied the ones from the imported css files (blueminor.css or redminor.css) are ignored.

The import works since at page load IE7 applies correctly the rules defined in the imported styles.

Also as a workaround, if I dynamically remove the cssLink element from the DOM, and then I re-create it works correctly in all browsers including IE7.

So if you do this instead things will work as supposed:

function replaceRed() {		
	var cssFile = document.getElementById('cssLink');
	var par = cssFile.parentNode;
	par.removeChild(cssFile);
	cssFile = document.createElement('LINK');
	cssFile.type = 'text/css';
	cssFile.id = 'cssLink';
	cssFile.media = 'all';
	cssFile.rel = 'stylesheet';
	cssFile.href = 'css/red.css';
	par.appendChild(cssFile);
}

function replaceBlue() {		
	var cssFile = document.getElementById('cssLink');
	var par = cssFile.parentNode;
	par.removeChild(cssFile);
	cssFile = document.createElement('LINK');
	cssFile.type = 'text/css';
	cssFile.id = 'cssLink';
	cssFile.media = 'all';
	cssFile.rel = 'stylesheet';
	cssFile.href = 'css/blue.css';
	par.appendChild(cssFile);
}	

Download the test case: http://remus.pereni.org/fisiere/div/iebug/iebug.zip

View the test case: http://remus.pereni.org/fisiere/div/iebug/

May 19th, 2007

Daily Rumblings

Like usually sporadic log updates :( . I've got two weeks ago my Visor, was not the Ice model as I requested but the Graphite (that's how it works around here). Doesn't really matter, what does is that is cool. Tons of software and the gadget is quite practical. As a matter of facts that is the reason why there are more Palms sold than Psions. Even if an Psion is more advanced from almost any aspect, Palm's are more practical. Again a matter of usability. Made the mistake to upgrade to Mandrake 8.0. XEmacs-JDE broke, font aliasing not working, Gimp not working, MidnightComander strange behavior, ethernet driver with bugs, Abiword managed to start only once. The nVidia drivers which always where decently supported are behaving strangely and I could go on and on. The sad part is that starting with Mandrake 7.0 every new release sucked more and that I ordered the package before trying it. So when I decide to pay for a Linux distribution, I choose the wrong one. Maybe is time to switch to Debian or RedHat. Spent some time watching the #rdfig channel on irc.openprojects.net, and runned into Tim Berners Lee. I was kind of shocked, I couldn't believe that such celebrities are touchable. On the other hand is the working place of some other famous peoples like Ed Dumbil, Dan Connolly, ... Fboutinally, found a way to improve my team and to provide negative feedback. We bout some cool books, but nobody read them. So now every day one of us is preparing a half an hour speech about something (from the books). The book we started with is Martin Flowler's Refactoring. The guys love it plus that if you are too late, you've got to make the speeches for the whole week ;) Information System Architecture - One of the recurring themes of my career is how to structure sophisticated information systems, particularly those that operate across multiple processing tiers..., Martin Flowler

June 16th, 2001


So, who is Remus?

Remus Pereni is a 32 years old free thinker, IT addict, who lives, works, and wonders about the meaning of life, relations, human nature, IT, technologies, clients, value and business from Satu Mare, Romania. More

Calendar

January 2009
M T W T F S S
« May    
 1234
567891011
12131415161718
19202122232425
262728293031  

Categories

Posts by Month

Feeds