getLocale equivalent in javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SanjivaniPant
    New Member
    • Apr 2008
    • 8

    getLocale equivalent in javascript

    Hi,

    Does anybody know how to get client locale in javascript. I know vbscript GetLocale function but I am searching its equivalent in javascript.

    Some sites have mentioned using getLocale(reque st). Here request is HTTPRequest object but I can not make HTTP Request object in javascript. Please tell me how to use it.

    Thanks
    Sanjivani
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    With JavaScript, some browsers support browser/user/systemLanguage/language properties of the Navigator object. See this example.

    Comment

    • SanjivaniPant
      New Member
      • Apr 2008
      • 8

      #3
      Originally posted by acoder
      With JavaScript, some browsers support browser/user/systemLanguage/language properties of the Navigator object. See this example.
      Hi.

      Thanks for your reply.. I want client machine locale, not browser langauge. navigotor will give me browser language. If I use sysemlangauge then it works in IE but not in mozilla :(

      How about making http request and getting detail from http request header? At present I am searching for how to read http request header in javascript. If you know, please share your knowledge.

      ~Sanjivani

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You can use just navigator.langu age in Mozilla/Firefox.

        When you make an http request, would that not be for the server?

        Comment

        • SanjivaniPant
          New Member
          • Apr 2008
          • 8

          #5
          Originally posted by acoder
          You can use just navigator.langu age in Mozilla/Firefox.

          When you make an http request, would that not be for the server?

          We can make request from javascript. Have a look onto following link.
          http://www.jibbering.c om/2002/4/httprequest.htm l

          I could manage to make http request but I could not see system language in response :(

          navigator.langu age will give me broswer langauge or client system language?

          Thanks
          Sanjivani

          Comment

          • SanjivaniPant
            New Member
            • Apr 2008
            • 8

            #6
            navigator.langu age in mozilla always returns en-US

            ¬Sanjivani

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Give an example of what you want returned.

              Comment

              • SanjivaniPant
                New Member
                • Apr 2008
                • 8

                #8
                Originally posted by acoder
                Give an example of what you want returned.
                I want to know what is the language set in regional setting on client machine. If client machine has UK regional setting then I want to know that even browser usess US. So I want javascript code for this which should run on mozilla, IE, Safari, Opera.

                ¬Sanjivani

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  I don't think there's a cross-browser way to get this information using JavaScript, but I could be be proved wrong.

                  The http request would be to the server, not the client.

                  Comment

                  • SanjivaniPant
                    New Member
                    • Apr 2008
                    • 8

                    #10
                    Originally posted by acoder
                    I don't think there's a cross-browser way to get this information using JavaScript, but I could be be proved wrong.

                    The http request would be to the server, not the client.
                    Right, but request will be from client to server. So we can make XMLHTTPRequest object in javascript for a dummy page. But Only thing I could not figure out is , how to read request header.

                    [CODE=javascript] var xmlhttp=false;
                    if (!xmlhttp && typeof XMLHttpRequest! ='undefined') {
                    try {
                    xmlhttp = new XMLHttpRequest( );
                    } catch (e) {
                    xmlhttp=false;
                    }
                    }
                    if (!xmlhttp && window.createRe quest) {
                    try {
                    xmlhttp = window.createRe quest();
                    } catch (e) {
                    xmlhttp=false;
                    }
                    }
                    xmlhttp.open("H EAD", "ReturnHeader.h tm",true);
                    xmlhttp.onready statechange=fun ction() {
                    if (xmlhttp.readyS tate==4) {
                    //alert(xmlhttp.g etRequestHeader (0));
                    //Here we have to write code of getting request header, but how? gerRquestHeader method is failing here
                    }
                    }
                    xmlhttp.send(nu ll)[/CODE]
                    Last edited by acoder; Apr 3 '08, 03:18 PM. Reason: Added code tags

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      I don't think you can get the request header. You can get the response header, but that's probably not much use for you here.

                      Comment

                      Working...