Javascript language detection :: language based redirection

Reply Wed 30 Jul, 2003 01:56 am
This javascript is used to detect a visitor's language in his/her browser and redirect to the page of your choice. It also has a default page.

Language abbreviations for browsers

Here is the script:

Code:<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
if (navigator.appName == 'Netscape')
var language = navigator.language;
var language = navigator.browserLanguage;
if (language.indexOf('en') > -1) document.location.href = 'english.html';
else if (language.indexOf('de') > -1) document.location.href = 'german.html';
else if (language.indexOf('it') > -1) document.location.href = 'italian.html';
document.location.href = 'defaultpage.html';
// End -->
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 2 • Views: 39,390 • Replies: 10
No top replies

Craven de Kere
Reply Wed 30 Jul, 2003 02:01 am
If you have any questions, need help or want a PHP language redirection script let me know.
Reply Mon 20 Jul, 2009 10:05 am
@Craven de Kere,
How i have to do, if want to put the detection for all browsers?

Do i have to copy paste all the script and each time change the name of the browser or i have to specify all the browsers on the general script?

Thank you, waiting the answer.
Robert Gentel
Reply Mon 20 Jul, 2009 12:38 pm
I'm not sure what you are asking.

If the script doesn't work across browsers that may be due to different JavaScript implementations, and it may not be possible to read local language settings with JavaScript in some browsers.
Reply Tue 21 Jul, 2009 07:17 am
@Robert Gentel,
So you want to say, that this script, as it is, should work for every browser?

Because the place that it says "Netscape" i thought i need to change that by, example, FF or IE.
Robert Gentel
Reply Tue 21 Jul, 2009 09:46 am
It probably doesn't work in every browser. But that Netscape code doesn't mean it only works for Netscape. Give it a try and see if it works.
Reply Tue 21 Jul, 2009 02:46 pm
@Robert Gentel,
I got it, thanks dude, this will be a good solution then, cause the company i work for don't want to use PHP, they use ASP, and this sucks, the problem is that i'm good programming in Asp.net, i can read, but not code.
0 Replies
Reply Fri 4 Jun, 2010 06:30 am
I have no programing expirience and have use MS Front page to creat a web site for our small company. We do business in English and French so I have two different web sites. We have a home page that has an English or French selector butone, but over 50% of customers bounce out of that page. I would like to eliminate it. Do I just copy this code into the HTML of that first page and change the It for Fr. How does the code tell the incoming browser which page to go to? Do you not need to add an adress like, HTTP//www.sumthing//forexample?

Robert Gentel
Reply Sat 5 Jun, 2010 10:24 am

Welcome to a2k.

The part that tells the browser where to go are where it does this:

Code:document.location.href = 'italian.html'

It's using relative paths within the folder, so that above would direct the browser to the "italian.html" file in the same folder.

Replace what's in the quotes with a URL and it will redirect to that URL.
0 Replies
Reply Mon 6 Feb, 2012 03:05 am
@Craven de Kere,
Can you contact me about your script?
Thanks a lot!
0 Replies
Reply Sun 25 Mar, 2012 05:57 am
Thanks for the java script.
0 Replies

Related Topics

How does one uninstall a program? - Question by Woollcott
Adding a JavaScript 'Copy to Clipboard' - Discussion by BobbyDouglas
JavaScript: OnSelect question - Discussion by neocode
Javascript - Control C textarea script - Discussion by Craven de Kere
2018123 - Question by ibk1995
javascript loops for - Question by vartul agnihotri
  1. Forums
  2. » Javascript language detection :: language based redirection
Copyright © 2022 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 08/15/2022 at 09:52:35