# Conditional if statement for browser identification



## Duckman69 (Jun 26, 2007)

im working with a script im trying to get working any1 have any ideas where i might have gone wrong here... heres what i got....


----------



## MMJ (Oct 15, 2006)

```
var ua = navigator.userAgent;

if (ua.match('Opera')){
	document.write('<link rel="stylesheet" href="operastyle.css" type="text/css"');

}
else{
	document.write('<link rel="stylesheet" href="normalstyle.css" type="text/css"');

}
```
I put it in PHP tags for highlighting. Obviously, though, it is really JavaScript.


----------



## Duckman69 (Jun 26, 2007)

hey thanks for the revision, i cant seem to get it to work though i bet it works but i just am doing something wrong i think... im new to css, been learning alot latly doing alot of reading on it... but im still very lost on some things...

Below is what i added to the header... do i need a operastyle.css and normalstyle.css though and what would i put in them really sorry im so bad with this stuff hopfully i get it down quickly and can start to shed some light with other ppl's issues on it


----------



## Duckman69 (Jun 26, 2007)

i tried making the .css for them with the <body text => lines i have up there .... tried this with the statement in the header also then removed it so it was only being referenced from the .css files  no luck though...


----------



## MMJ (Oct 15, 2006)

I think this is what you are trying to do. 


```
if (ua.match('Opera')){
document.write('<link rel="stylesheet" href="operastyle.css" type="text/css"');
}
else{
document.write('<link rel="stylesheet" href="normalstyle.css" type="text/css"');
}
```


----------



## MMJ (Oct 15, 2006)

the code above has been edited.


----------



## Duckman69 (Jun 26, 2007)

any hints on what i may be doing wrong? i tired that script the exact way it is, also as a java script (both in the header).... then i tried removing that, and adding the code both ways into the .css files i have  nothing... all i have to have in the operastyle and normalstyle.css is that code right?

if (ua.match('Opera')){
document.write('<link rel="stylesheet" href="operastyle.css" type="text/css"');
}
else{
document.write('<link rel="stylesheet" href="normalstyle.css" type="text/css"');
}

i've given myself a headache today with all this i feel like im in a rat maze running in circles, and ill never get my damn cheese... lol i gotta get outa the house for now, i really appreciate your patients and help with me the last day or 2 i've been trying to cram in alota stuff before i leave for boot camp


----------



## MMJ (Oct 15, 2006)

put your code in a page then upload it somewhere on the net.

i'll take a look and see whats wrong.


----------



## WendyM (Jun 28, 2003)

Just out of curiosity, is there a reason why you need the text to be a different color in Opera than in other browsers?


----------



## Duckman69 (Jun 26, 2007)

i was trying to take the easy way out of a problem im having... plus i figure its good to know... http://www.freewebs.com/fallingrain11/1.htm


----------



## MMJ (Oct 15, 2006)

Duckman69 said:


> i was trying to take the easy way out of a problem im having... plus i figure its good to know... http://www.freewebs.com/fallingrain11/1.htm


You are using the old javascript in that page


----------

