SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2008
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detect Vista OS with JavaScript

    I was wondering if anyone knows a good way of detecting Vista OS in JS...

    I need a method to detect Vista for one of my websites so I could load an other StyleSheet file if a visitor has Vista.


    TIA.
    Proud member of this community.
    ____________________________

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    JavaScript is not even able to reliably detect what browser is being used. The only field available to test for such things (useragent) can be set to anything by the browser owner. Even where it is left set to the default value it will not recognise operating systems released after the browser was released and so for everyone still using IE6 the default operating system the useragent will report is for those running Windows 2000/XP/Vista is Windows NT.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2008
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I know that... but I was kind of hopping, you know...? *bitter smile*

    I wonder how Google knows, because when I checked the statistics in the Webmaster Tools for that site, it showed a number of visitors having the Vista OS...(I'm pretty sure they weren't guessing).

    I should most definitely be looking for a server-side code...Does it happens to know of any, or at least a place where I might go and look for one? Could be in C# or VB.NET, it doesn't really matter that much...

    *until then I'll keep looking around, maybe I get lucky*
    Proud member of this community.
    ____________________________

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You won't get it done with javascript-
    you can detect the windows os name (xp,nt,2000,vista) with java (google browser hawk), but only if the browser is running IE,and has java turned on.

    There are always c and c# methods, but again, they have to run from the server,
    usually as part of a session log-on script.

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2008
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't mind running the check on the server side. I find it a better option to javascript actually.

    The website hosting package doesn't have included java support so I'm stick to either VB or C#.
    Proud member of this community.
    ____________________________

  6. #6
    SitePoint Member actionAction's Avatar
    Join Date
    Jun 2008
    Location
    STL
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Though it's true that this method is not reliable, it will sometimes work (and is the only available client side option):

    Code:
    navigator.userAgent.indexOf("windows NT 6.0")
    With PHP you can use (though it can be unreliable as well):

    PHP Code:
    $_SERVER['HTTP_USER_AGENT']; 

  7. #7
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Best bet is checking that "navigator.userAgent" string. It's going to work in cases where things are setup properly on the clients end.

  8. #8
    SitePoint Zealot
    Join Date
    Apr 2008
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by actionAction View Post
    Though it's true that this method is not reliable, it will sometimes work (and is the only available client side option):

    Code:
    navigator.userAgent.indexOf("windows NT 6.0")
    With PHP you can use (though it can be unreliable as well):

    PHP Code:
    $_SERVER['HTTP_USER_AGENT']; 
    I'll try your suggestion. Thank you.
    Proud member of this community.
    ____________________________

  9. #9
    SitePoint Zealot
    Join Date
    Apr 2008
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    navigator.userAgent.indexOf("Windows NT 6.0")
    I guess that should do it for the moment (that is until I find a server-side solution). I tested it in XP on VM and from my comp which has Vista installed.

    Thanks again.
    Proud member of this community.
    ____________________________

  10. #10
    SitePoint Member actionAction's Avatar
    Join Date
    Jun 2008
    Location
    STL
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem, glad to help!


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
  •