HighDots Forums  

Re: browser detection and css

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: browser detection and css in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ian Collins
 
Posts: n/a

Default Re: browser detection and css - 10-01-2006 , 03:37 PM






jnc3196 (AT) googlemail (DOT) com wrote:
Quote:
Help needed, the script below detects the correct browser but doesn't
select the correct CSS file. Also how to call it from an external js
file so as not to repeat it in every page.

Why don't you just use IE specific conditional includes?

<!--[if IE ]>
<link ..... />
<![endif]-->


--
Ian Collins.


Reply With Quote
  #2  
Old   
totalstranger
 
Posts: n/a

Default Re: browser detection and css - 10-01-2006 , 09:01 PM






On or about 10/1/2006 3:37 PM, it came to pass that Ian Collins wrote:
Quote:
jnc3196 (AT) googlemail (DOT) com wrote:
Help needed, the script below detects the correct browser but doesn't
select the correct CSS file. Also how to call it from an external js
file so as not to repeat it in every page.

Why don't you just use IE specific conditional includes?

!--[if IE ]
link ..... /
![endif]--


The following works for me and allows IE7 and all other browser to use
my default css. However, it does not pass the W3C HTML validation.

<!--[if lte IE 6]>
<LINK REL="stylesheet" TYPE="text/css" HREF="CSS/IE5.css">
<![endif]-->
<![if gte IE 7]>
<LINK REL="stylesheet" TYPE="text/css" HREF="CSS/Default.css">
<![endif]>


Reply With Quote
  #3  
Old   
jnc3196@googlemail.com
 
Posts: n/a

Default Re: browser detection and css - 10-02-2006 , 11:18 AM



on Oct 2 2006 2:01 am totalstranger wrote:

Quote:
The following works for me and allows IE7 and all other browser to use
my default css. However, it does not pass the W3C HTML validation.
Thanks for the responces, I'll try this out.

"If you tell what kind of particular discrepancies you want to deal
with, we'll find a working modern solution.", VK

Problem: The web site looks different under Firefox and Iexplorer 6.
The solution is to load a different CSS file depending on the browser.
I would like to link each page to a javascript browser detection script
so I don't need to paste the script into every html file.



Reply With Quote
  #4  
Old   
Matt Kruse
 
Posts: n/a

Default Re: browser detection and css - 10-02-2006 , 11:31 AM



jnc3196 (AT) googlemail (DOT) com wrote:
Quote:
Problem: The web site looks different under Firefox and Iexplorer 6.
This is not necessarily a problem. Why must it look identical?

Quote:
The solution is to load a different CSS file depending on the browser.
A better solution might be to write more portable, bullet-proof css.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com




Reply With Quote
  #5  
Old   
jnc3196@googlemail.com
 
Posts: n/a

Default Re: browser detection and css - 10-02-2006 , 12:47 PM



Mon, Oct 2 2006 4:31 pm Matt Kruse wrote:

Quote:
This is not necessarily a problem. Why must it look identical?
I use Firefox, most of the viewers will be using Iexplorer. The fonts
are different sizes and images don't position correctly.

Quote:
The solution is to load a different CSS file depending on the browser.

A better solution might be to write more portable, bullet-proof css.
I've tried such portable CSS files. They don't word as advertised and I
don't understand enough of the syntax to write one. How difficult is it
of the browser developers to get them displaying the same.

Here's one that shows promise ..
http://www.digiways.com/articles/php...cssmethod.html



Reply With Quote
  #6  
Old   
Matt Kruse
 
Posts: n/a

Default Re: browser detection and css - 10-02-2006 , 01:06 PM



jnc3196 (AT) googlemail (DOT) com wrote:
Quote:
I use Firefox, most of the viewers will be using Iexplorer. The fonts
are different sizes and images don't position correctly.
Do you have an example url?
If images position incorrectly just because of font size, you are probably
misusing css or need to reconsider your design.

Quote:
Here's one that shows promise ..
http://www.digiways.com/articles/php...cssmethod.html
Yuck. Don't look at the user agent to serve up different css! This is always
bad.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com




Reply With Quote
  #7  
Old   
jnc3196@googlemail.com
 
Posts: n/a

Default Re: browser detection and css - 10-02-2006 , 02:41 PM



Quote:
Do you have an example url?
Not yet, at the rate I'm going at maybe in a few weeks

Quote:
Yuck. Don't look at the user agent to serve
up different css! This is always bad.
Ok, so its back to a single css with conditionals for Iexplorer. By the
way this script does work except it won't load opera.css under Opera
9.02

document.write('<link rel="stylesheet" href="http://somesite.com/');
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf('opera') != -1) document.write('opera.css');
else if (agt.indexOf('gecko') != -1) document.write('mozilla.css');
else if (agt.indexOf('msie') != -1) document.write('iexplorer.css');
else document.write('default.css');
document.write('" type="text/css">');



Reply With Quote
  #8  
Old   
Ian Collins
 
Posts: n/a

Default Re: browser detection and css - 10-02-2006 , 03:22 PM



Matt Kruse wrote:
Quote:
jnc3196 (AT) googlemail (DOT) com wrote:

Problem: The web site looks different under Firefox and Iexplorer 6.


This is not necessarily a problem. Why must it look identical?


The solution is to load a different CSS file depending on the browser.


A better solution might be to write more portable, bullet-proof css.

I normally end up with a few entries in an IE specific css file to cope
with the things IE doesn't implement, like :hover.

I don't think it's possible to get table borders consistent without IE
specific entries.

--
Ian Collins.


Reply With Quote
  #9  
Old   
Matt Kruse
 
Posts: n/a

Default Re: browser detection and css - 10-02-2006 , 03:37 PM



jnc3196 (AT) googlemail (DOT) com wrote:
Quote:
Ok, so its back to a single css with conditionals for Iexplorer.
Or not. Just design css that works in both. If there are compatability
problems, use different features or change your design to not rely on
unimplemented features.

There is going to be a lot of pain in the world when IE7 is released,
because people have used hacks and browser-detection to serve up different
css to different browsers. IE7 will support css much better than IE6, and
detection/hack scripts that previously tried to make sites look good in IE6
will start making sites look _bad_ in IE7.

BTW, if you aren't using a strict doctype, start with that. Using
cross-browser css becomes much easier once you are in strict mode.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com




Reply With Quote
  #10  
Old   
VK
 
Posts: n/a

Default Re: browser detection and css - 10-02-2006 , 05:17 PM




jnc3196 (AT) googlemail (DOT) com wrote:
Quote:
Problem: The web site looks different under Firefox and Iexplorer 6.
That is way too much of philosophy to be practical IMHO. Unless you are
doing some cutting edge stuff like behaviors/bindings/SVG/VML: you are
just dealing with simple box model discrepancies (x is lefter than
should, y is righter than I expect). Just read the "must have" article
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnie60/html/cssenhancements.asp>
(a lot of good guys went out of business before this was forced to be
implemented, so at least read it). Then place one of suggested
DOCTYPE's to unify the fox model and try it over. Ask at ciwas for more
help.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.