SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict langedav's Avatar
    Join Date
    Apr 2002
    Location
    Rotterdam, The Netherlands
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post choose browser style script

    hello everybody,

    Today i finished coding my old website into xhtml.

    All pages are 100% Transitional, which is good offcourse. Now the way they are displayed on each browser is very different so i guess i have to make a different stylesheet for each different browser.

    What i need now is a (java)script that checks the browser version and depending on the browser writing the code for which style to use.

    I have this script:
    Code:
     
     if (navigator.appName=="Netscape")// netscape 
      document.write('<link href="/styles/ns.css" rel="stylesheet" type="text/css" />')
     else if (navigator.appName=="Microsoft Internet Explorer")//Internet explorer
      document.write('<link href="/styles/ie.css" rel="stylesheet" type="text/css" />')
     else //if not IE OR NS then Set default
      document.write('<link href="/styles/ie.css" rel="stylesheet" type="text/
    But i guess it does not cover all browsers. Can anyone help me out here with some sort of a "super script" which covers all browser (versions)?

  2. #2
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesn't exist, sorry

    In two clicks, I can make my browser look like Opera to Mozilla/3 to IE 6.

    You really can make a CSS site work without going too browser specific.

    Douglas

    ---
    PS: Go for XHTML Strict
    Hello World

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Langedav,

    Why not just use one stylesheet for all browsers? It's not too difficult at all. As a matter of fact, it's probably easier than the convoluted script you want, which would only work if scripting is enabled and the browser in question is telling the truth about which browser they are. Every browser can disable scripting, and Opera, Safari, and Firebird have a habit of being able to lie about which browser they are. If I'm using Opera 5 on a Mac, I can tell you I'm using IE6/Windows and your script would fail.

  4. #4
    SitePoint Evangelist S7even's Avatar
    Join Date
    Jun 2002
    Posts
    481
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just use common CSS and then use some CSS hacks or hide parts of CSS from specific browsers.
    This way your site can look good in all modern browsers and ok even in older ones.
    Check out these links:
    http://w3development.de/css/hide_css_from_browsers/
    http://www.positioniseverything.net/

  5. #5
    SitePoint Addict langedav's Avatar
    Join Date
    Apr 2002
    Location
    Rotterdam, The Netherlands
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE='S7even']Just use common CSS and then use some CSS hacks or hide parts of CSS from specific browsers.
    This way your site can look good in all modern browsers and ok even in older ones.
    Check out these links:
    http://w3development.de/css/hide_css_from_browsers/
    http://www.positioniseverything.net/[/QUOTE]

    Okay thanks everybody, i guess i have to get into it a little deeper. :-)

  6. #6
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Furthermore you could assume approximately 10% of the user-agents used in the real world have JavaScript disabled, or are not capable of running the JavaScript.

  7. #7
    SitePoint Addict langedav's Avatar
    Join Date
    Apr 2002
    Location
    Rotterdam, The Netherlands
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i allready removed the javascript ;-)

    But why is it allways the same. Just when you think you know it all you find out there is soooo much more to explore

  8. #8
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by langedav
    i allready removed the javascript ;-)

    But why is it allways the same. Just when you think you know it all you find out there is soooo much more to explore
    It keeps you on your toes


Bookmarks

Posting Permissions

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