Javascript help

Hi, im new here and also new with javascript and was wondering if you guys could help me out?

My friend has been asking me to help him out with a game he has been building and I was wondering if you guys could help me because im stumped :stuck_out_tongue:

Basically, what he wants to be able to do is when you load the URL the game is on i.e. ‘myfriendsgame.com/game’ he wants it to be able to detect what language the game should be loaded in and whats the url to be similar to this:

'myfriendsgame.com/game/index.html?langauge=UK or DE or IT etc.

I wouldnt know how to do this so I was wondering if someone would be able to help me out?

Thankyou very much in advance.

Charlie

Edit: I just heard from him that basically what he wants to do is to ‘Pass a query string into flash’ I dont know how to do this either haha.

Since the script will be reading the language set in the user agent string (which the browser sends when it asks for a page), your friend will have to be aware that the browser language may not be the language spoken by the user (I have browsers in several languages, but if I’m using a browser in a public area in another country, its language is often set to a local language, and not one I speak… happened recently at a conference in Pisa, Italy!).

Also, this will likely have to be a back-end script, or, it would be better as a back-end script. This back-end script will run regardless of whether the user has Javascript enabled or not (unless this is a requirement for the game, in which case, using Javascript is maybe ok), and can talk directly tot the server (who will supply the correct url).

Hm, wait, you mention Flash. Is this going to be done with Javascript, or with Actionscript?

I’d say, you’ll have to ask for the user agent string. I don’t know if that can easily be done.

Example, my current user agent string:

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Ubuntu/9.10 (karmic) Firefox 3.5

Your server will always get the language as
HTTP_ACCEPT_LANGUAGE:en-us,en;q=0.5 (example)
but browsers don’t always put the language in the same place, and the Javascript language-detection out there seems stable for… IE and Netscape. Which doesn’t exactly cover all users anymore : )

So I’m still thinking this is better done on the server side. Flash may need to get this straight from the server or from a server-side script.

i think he wants to use JavaScript to detect the Url.

like,

location.href = ‘myfriendsgame.com/game/index.html?langauge=UK’;
location.href = ‘myfriendsgame.com/game/index.html?langauge=IT’;