JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old June 20th, 2004, 05:53 AM
lordhart lordhart is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 lordhart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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...

Reply With Quote
  #2  
Old June 20th, 2004, 06:32 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old June 20th, 2004, 07:19 AM
lordhart lordhart is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 lordhart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old June 20th, 2004, 07:23 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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.

Reply With Quote
  #5  
Old June 20th, 2004, 09:04 AM
EiSa EiSa is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Norway
Posts: 184 EiSa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 24 sec
Reputation Power: 6
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.

Reply With Quote
  #6  
Old June 20th, 2004, 09:17 AM
lordhart lordhart is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 lordhart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #7  
Old June 20th, 2004, 07:33 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Browser Check to Apply Correct CCS style...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway