Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Css and Browser switching

Status
Not open for further replies.

danjapro

Programmer
Aug 27, 2004
54
US


Does anyone know of a javascript or some coding that allows you to switch style sheets based on the borowser being used.

I tried this script and it does not work.


<SCRIPT LANGUAGE="Javascript">
<!-- var bIsIE = navigator.appName == "Microsoft Internet Explorer" var bIsIE4 = bIsIE && navigator.appVersion.indexOf("4.0") > -1
if (bIsIE4)
{ sCSS = '<LINK REL="stylesheet" TYPE="text/css" HREF="nfi2.css">' }
else
{
if (bIsNS)
{ sCSS = '<LINK REL="stylesheet" TYPE="text/css" HREF="nfi2mo.css">' } }
document.write(sCSS) file://-->
</SCRIPT>
 
Let's go about it a little differently. Why do you need different stylesheets for different browsers? If you take a look at the modern browsers (IE6, Mozilla, FF, Netscape 7, Opera 7, Safari...) they will render the pages more or less the same (maybe not pixel perfect, but close enough). What exactly are you trying to exclude with that script? Except the 10% of people that surf with JS turned off.
 
I have a website that certain pages looks to different in IE as to in firefox.

If I makes changes in css to fit fire foxe. the piece of crap IE chagnes. Now I have the chages set in two different Css that makes both borwsers appear alike.

Is there a script to do this and it works.
That all. Where is someon using fire fox will see the website similar to someone using IE.
 
This provides an insight but does not help.

I need a script taht will detect the broser and then load the appropriate css.

This has to be out there. Anyone.
 
If you insist, see forum216.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
danjapro, I am sorry you did not take a few minutes to look at the link I posted. If you did, you would notice that it shows how to hide CSS from certain browsers which means about the same as loading different css for different browsers. That method is much more reliable, though correct coding still beats them both. If you need to be walked through, try this:
Code:
<link rel="stylesheet" src="myIEcss.css" type="text/css" />
<style type="text/css"><!--
@import url(myFFcss.css) screen;
--></style>
This will load both css in FF and only IE css in IE. If you are defining the same stuff in your FF css, your IE css will be overwritten with FF css.
 
Thanks for the input.

but this still leaves me out there .........
I need for the two spereate css to load based on browsers. I dont' need them cross paltfroming. Some of the defines in my FF css is the same name and id as in my IE Css.

I did not use the method becaue it is not what I am looking for.

I know there has to be this script out there.

anyone help me.
 
why not define the common elements and names in a single CSS file and then use import a browser specific one to extend the current classes / add new classes depending on the browser.
 
I know there has to be this script out there.
Errr.. yes:
I really urge you to listen to what the people here are telling you, though. If you're going to ask questions in an expert forum, you should be ready to listen to expert opinion that you're going about things in the wrong way.

Otherwise, just use Google.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Cool, that means I can break your pretty site by:
- making my browser report to be a different browser
- using a browser that isn't Mozilla or IE (what does it look like in Links or Lynx)
- turning off JS (which I do a lot of the time anyway
- Loading my own local style sheet (which I can do, but typically don't).

 
How about IE conditional comments?
Code:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="IESpecific.css">
<![endif]-->
Other browsers will ignore it. No UA string checks, no JS.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top