Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ASP Javascript string splitting

Name: Anonymous 2009-03-18 9:04

Does anyone know why this doesn't work:

<%@Language="JScript"%>
<html><body><%

var AL = Request.ServerVariables("http_accept_language");
var ALA = AL.split(",");

%></body></html>


It fails on the line with the split method with error Microsoft JScript runtime (0x800A01B6) Object doesn't support this property or method, but I don't see why.

Name: Anonymous 2009-03-18 9:09

Probably because the object doesn't support that property or method.

Name: Anonymous 2009-03-18 9:30

>>2
No, it's just because ASP doesn't like him. It's there, why wouldn't it be?

Name: Anonymous 2009-03-18 9:39

AL is probably not a string. It's most likely a COM type, a collection of some sort. I wouldn't be surprised, anyway.

Name: Anonymous 2009-03-18 9:48

On reflection, you probably meant Request.ServerVariables["http_accept_language"] or something like that.

Request.ServerVariables("http_accept_language") is pig disgusting VBScript syntax.

Name: Anonymous 2009-03-18 10:01

Name: Anonymous 2009-03-18 12:36

Well, I still don't know why it's not a proper String object, but I worked around it by wrapping it in new String().

Name: Anonymous 2009-03-18 12:36

Also, have some code:

<% @Language="JScript" %><%

/**** LANGUAGE REDIRECTION CODE ****/


/* Couple of useful methods to start off with */

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"") }

function inArray(a, s)
{
  for(var i in a)
  {
    if (s == a[i])
    {
      return true
    }
  }
  return false
}

/* ParseAcceptedLanguageHeader returns an array of accepted languages, ordered
   by decreasing quality. Each element of the array is an array of which the
   first element is the main language code (typically from ISO 639-1), the
   second element is the subcode (usually either blank or an ISO 3166 two-
   letter country code, and the third element is the quality value. */
  
function ParseAcceptedLanguageHeader()
{
  var AL = []
  var AL1 = new String(Request.ServerVariables("http_accept_language")).split(",")
  for (var n in AL1)
  {
    AL2 = AL1[n].split(";",2)
    AL3 = AL2[0].trim().split("-",2)
    Language = AL3[0].trim()
    if (AL3[1])
    {
      SubLanguage = AL3[1].trim()
    }
    else
    {
      SubLanguage = ""
    }
    Quality = 1
    if (AL2.length > 1)
    {
      AL4 = AL2[1].split("=",2)
      if (AL4[0].trim().toLowerCase() == "q")
      {
        Quality = parseFloat(AL4[1])
        if (Quality == undefined)
        {
          Quality = 0
        }
      }
    }
    if (Quality > 0) {
      AL.push([Language, SubLanguage, Quality])
    }
  }
  AL.sort(function(l,r) { return r[2] - l[2] })
  return AL
}

/* DetermineBestLanguage accepts as its only parameter an array of allowed
   languages, of which the first element of the array is the default
   language if no better match can be made. It compares this list against
   the list of allowed languages, and returns the first match if one can
   be made. */

function DetermineBestLanguage(AllowedLanguages)
{
  AcceptedLanguages = ParseAcceptedLanguageHeader()
  for (var i in AcceptedLanguages)
  {
    for (var j in AllowedLanguages)
    {
      if (AcceptedLanguages[i][0].toLowerCase() == AllowedLanguages[j].toLowerCase())
      {
        return AllowedLanguages[j]
      }
    } 
  }
  return AllowedLanguages[0]
}

/* Redirect based on either the language cookie value, or if that doesn't
   exist or is invalid, determine the best language to use from the
   Accept-Language header, and set the cookie & redirect based on that */
  
AllowedLanguages = ["en","fr","de","es"]

ChosenLanguage = Request.Cookies("language")
if (ChosenLanguage=="" || !inArray(AllowedLanguages, ChosenLanguage))
{
  ChosenLanguage = DetermineBestLanguage(AllowedLanguages)
  Response.Cookies("language") = ChosenLanguage
}

Response.Redirect(ChosenLanguage+"/")
 
%>

Name: Anonymous 2009-08-16 22:51

Lain.

Name: Anonymous 2010-12-06 9:49

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-02-03 8:08

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List