Computing.Net > Forums > Web Development > Java serves CSS to diff'nt browsers

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java serves CSS to diff'nt browsers

Reply to Message Icon

Name: robber2
Date: November 9, 2004 at 16:22:26 Pacific
OS: w xp
CPU/Ram: 2 gig celeron, 256 MB
Comment:

Somewhere I saw a way to include Java script in a web page to serve a different .css file (stylesheet) to different browsers (to try to sidestep various browser specific bugs). Does anyone know how to do that? Thx!



Sponsored Link
Ads by Google

Response Number 1
Name: Dr. Nick
Date: November 9, 2004 at 16:39:17 Pacific
Reply:

I would imagine you could easily do it with any server-side scripting language. It's all a matter of finding the browser of the user and writing the correct code to the browser.

You could even do it easy enough in Javascript:

============================================================
<script>
if (navigator.userAgent.toLowerCase().indexOf('msie') + 1)
  //IE
  document.write('<link href="ie_css.css" rel="stylesheet" type="text/css">');
else
  //Other
  document.write('<link href="other_css.css" rel="stylesheet" type="text/css">');

</script>

See more here (about halfway down the page).

Just put that in place of your normal LINK> tag for the CSS file. If you don't want to do that you could also put it inside a function in the HEAD tag and change the HREF value of that LINK tag once the page has loaded.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Java serves CSS to diff'nt browsers

Apply diffrent .css to a webpage www.computing.net/answers/webdevel/apply-diffrent-css-to-a-webpage/4017.html

Apply diffrent .css to a webpage www.computing.net/answers/webdevel/apply-diffrent-css-to-a-webpage/4020.html

cant access webpage outside lan ..? www.computing.net/answers/webdevel/cant-access-webpage-outside-lan-/3045.html