Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-17-2007, 10:17 PM   PM User | #1
jaggedstone
New to the CF scene

 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jaggedstone is an unknown quantity at this point
Anyone good with javascript (browser detection --> css?)

Hi everyone. I don't know if anyone will know the answer to this but I figured I'd try anyway >.<

I am trying to use a browser detection script for my new website but I'm not quite sure how to make it to include Safari in the detection. Can anyone help? Thanks in advance.

Here is what I have so far:

Code:
if(-1 != navigator.userAgent.indexOf("MSIE"))
{
// Internet Explorer
document_write('.. rel="stylesheet" type="text/css" href="ie.css">');
}
else if (-1 != navigator.userAgent.indexOf("Mozilla"))
{
// Netscape
document_write('.. rel="stylesheet" type="text/css" href="netscape.css">');
}
else
{
// other
document_write('.. rel="stylesheet" type="text/css" href="other.css">');
}
jaggedstone is offline   Reply With Quote
Old 06-18-2007, 12:01 AM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,292
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
IMO you shouldn't rely on javascript serve up a stylesheet. You should be working to make your page appear the same in all browsers by coding properly in the first place.

This browser detect script may be what you want. Just remember JS CAN be disabled so the user wouldn't get your stylesheet.

http://www.quirksmode.org/js/detect.html
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 06-18-2007, 12:07 AM   PM User | #3
jaggedstone
New to the CF scene

 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jaggedstone is an unknown quantity at this point
Well, it's all coded properly...it's just a positioning problem in safari with the CSS. It works perfectly in all other browsers...its just safari that messes up >.<

Thanks for the link, I'll check it out.
jaggedstone is offline   Reply With Quote
Old 06-18-2007, 06:58 AM   PM User | #4
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
Quote:
It works perfectly in all other browsers...its just safari that messes up
Then why the need for three stylesheets?
If it does turn out the Safari does need a CSS tweak, there are better ways than using a js-dependent stylesheet.

e.g.…
Bill Posters is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:32 PM.


Advertisement
Log in to turn off these ads.