|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Browser Check to Apply Correct CCS style...
I've been trying to come up with a script which would do this, but it doesn't seem to be working. I want it to check the browser that is accessing the website, and then apply a specific style if it is Internet Explorer, or one for any other.
Heres what I've got: Code:
function BrowserCheck() {
if is_ie5up {
document.write("<link rel="stylesheet" type="text/css" href="default.css" />");
}
else {
document.write("<link rel="stylesheet" type="text/css" href="default.css" />");
}
}
And then I had in the <body> tag: Code:
onLoad="CheckBrowser();" Can anybody help me with this? I'd be really grateful... ![]() |
|
#2
|
||||
|
||||
|
My advice would be to ditch the browser check altogether - why make twice the work for yourself - whats the reasoning behind using the other stylesheet?
If you must use a detection script, just google "browser detect" - there's hundreds of scripts around. |
|
#3
|
|||
|
|||
|
I wanted it so it checks the browser and uses the right css file so that one appears in IE, and another in all standards compatible browsers. So things that would screw up in IE would still be able to work in browsers like Mozilla and Opera.
|
|
#4
|
||||
|
||||
|
Yeah - I assumed that. What I meant was, what exactly is it about your CSS that you are having problems with? 95% of the time, you shouldn't need to have two style sheets, as there are work arounds for the IE5/5.5 differences.
|
|
#5
|
|||
|
|||
|
I agree with stumpy, I never use different stylesheets. And I would avoid using javascript, even if they are few, there are some people that are surfing without javascript turned on.
If you need to use hack's for IE I would write them in the same CSS-file. Example 1: Code:
* html div#divname { /*IE hack */
some css-code
}
This code is only IE reading, not the other browsers as far as I know. Example 2: Code:
div#divname {
min-height: 100%;
height: auto !important;
height: 100%;
}
IE doesn't understand !important so that is also a solution. Example 3: Code:
<!--[if IE]><link rel="stylesheet" type="text/css" href="style.css" /><![endif]--> In this case only IE will read this stylesheet as far as I know, so if you absolutely wan't a seperat stylesheet for IE this could be a solution. And you can of course use a serverside script to grab a different stylesheet. |
|
#6
|
|||
|
|||
|
I tried them out and the 2nd one seemed to work well, thanks for that. I didn't originally want to use Javascript, but I thought it might of been the only way I'd achieve it...
Thanks again. ![]() |
|
#7
|
||||
|
||||
|
You may also want to read up on the box model problem that plagues IE5/5.5 here: http://www.positioniseverything.net.../box-model.html
For other IE problems, check out this section: http://www.positioniseverything.net/explorer.html - it offers a solution to IE problems. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Browser Check to Apply Correct CCS style... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|