SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict TegSkywalker's Avatar
    Join Date
    Nov 2001
    Location
    USA
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help detecting Safari 1.0 for proper stylesheet placement

    I am currently updating a few JavaScripts that use client side CSS selectors (selecting which .css file depending on the UA), and was curious what the User-Agent string is for the 1.0 release of Safari for the Macintosh. Any help would be great

    Second of all, I have this script and was wondering what would be an easy way to add Safari detection by using what I have. It's an old script but still works (usually link as a .js file):

    Code:
    var BROWSER_NAME = navigator.appName;
    var plat = navigator.appVersion;
    
    if (BROWSER_NAME == "Netscape" && plat.indexOf("Win") != -1) {
    document.write('<link rel="stylesheet" href="ns_win.css" type="text/css">');
    } else 
    
    if (BROWSER_NAME == "Microsoft Internet Explorer" && plat.indexOf("Win") != -1){
    document.write('<link rel="stylesheet" href="ie_win.css" type="text/css">');
    } else 
    
    if (BROWSER_NAME == "Netscape" && plat.indexOf("Mac") != -1) {
    document.write('<link rel="stylesheet" href="ns_mac.css" type="text/css">');
    } else 
    
    if (plat.indexOf("Mac") != -1 && plat.indexOf("MSIE") != -1) {
    	if (plat.indexOf("MSIE 5") != -1) {
    		document.write('<link rel="stylesheet" href="ie5_mac.css" type="text/css">');
    	}
    	else {
    		document.write('<link rel="stylesheet" href="ie_mac.css" type="text/css">');
    	}
    }
    
    // default style sheet loaded if no browsers match
    else {
    document.write('<link rel="stylesheet" href="default.css" type="text/css">');
    }

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    You can search for "Safari" in navigator.userAgent. On the other hand, it may be easier to code to standard CSS and HTML, only write one stylesheet, and not have to sniff browsers and maintain a bunch of CSS files.

  3. #3
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the string for the most recent version:

    Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/85 (KHTML, like Gecko) Safari/85
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  4. #4
    SitePoint Guru bronze trophy blufive's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To find out the user-agent script of a particular browser, try heading over to this page: http://www.ews.uiuc.edu/bstats/latest-week.html (warning: page can often be over 400kb, which might take a while on a modem...)

    It's the user-agent stats for a server at UIUC - and includes a list of EVERY user agent string detected in the last week or so, ranging from "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" (14000 visitors) to "testing" (1 visitor)

    Of course, finding the one you're looking for in the 4000+ user-agent strings they get every week can be a needle-in-a-haystack job...


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
  •