QUOTE(musya @ 30 Jun, 2009 - 06:40 PM)

Why doesnt it make sence, the php code outputs the correct path of the style sheets, and if that particular browser is being used then it should display that particular css link shouldnt it?
It doesn't produce syntatically valid javascript. Reading that is a bit like reading some code and all of the sudden the declaration of independance showing up. Ok, maybe not, but you are switching languages midstream.
Since I have a little bit better idea of what you want, I'll give you my other idea, although I still believe conditional comments are way better if you can separate the css appropriately (two lines versis all of this jazz, and more general to boot!).
To make it syntatically valid and possibly do what you want, try
CODE
<script type="text/javascript">
var browserName = navigator.appName;
var browserVer = navigator.appVersion;
if(browserVer.match("MSIE 7.0")){
document.write('<?php echo "<link rel=\"stylesheet\" href=\"".JURI::base()."/templates/$this->template/css/ie7.css\" type=\"text/css\"/>"; ?>');
}else if(browserVer.match("MSIE 8.0")){
document.write('<?php echo "<link rel=\"stylesheet\" href=\"".JURI::base()."/templates/$this->template/css/ie8.css\" type=\"text/css\"/>"; ?>');
}
</script>
so php parses and executes the page, and generates some thing like
CODE
<script type="text/javascript">
var browserName = navigator.appName;
var browserVer = navigator.appVersion;
if(browserVer.match("MSIE 7.0")){
document.write('<link rel="stylesheet" href="http://blabhblah.org/templates/mytemplate/css/ie7.css" type="text/css"/>');
}else if(browserVer.match("MSIE 8.0")){
document.write('<link rel="stylesheet" href="http://blabhblah.org/templates/mytemplate/css/ie8.css" type="text/css"/>');
}
</script>
which should make sense. the document.write will write into the browser's DOM for the page either one or the other (or neither!) link as the page is being parsed.
There are various reasons I don't like this, though.
1. what about support of MSIE 9 or other browsers?
2. lengthy
3. page not viewable without javascript support (although, frankly, I've been guilty of writing pages requiring javascript on numerous occasions...)
4. I'm not a fan of using document.write except in very few instances. (although this
might be acceptable.
5. If javascript breaks on your page previous to this script, you're screwed (it won't be executed, and the css won't load).
Now, lets take a look at the contender
CODE
<!--[if IE 7]><?php echo "<link rel=\"stylesheet\" href=\"".JURI::base()."/templates/$this->template/css/ie7.css\" type=\"text/css\"/>"; ?><![endif]-->
<!--[if gte IE 8]><?php echo "<link rel=\"stylesheet\" href=\"".JURI::base()."/templates/$this->template/css/ie8.css\" type=\"text/css\"/>"; ?> <![endif]-->
I can't think of any negatives, other than you're using MS's proprietary code (but that's a good thing as it precisely defines the target!). Pluse it's short and doesn't envolve javascript and supports the next version of MSIE, which I would guess should also be standards compliant.
This post has been edited by JayFCox: 1 Jul, 2009 - 05:21 AM