Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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">');
    }

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •