Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  173] [ 2]  / answers: 1 / hits: 18416  / 10 Years ago, tue, july 1, 2014, 12:00:00

I'm trying to send visitors that have browser language in English to an alternative site.
I was able to find this code but it's not working:



<script type=type/javascript>

var language = navigator.browserLanguage;

// alert(language);

if (language.indexOf('en') > -1) {
document.location.href = 'http://en.socialpos.com.ar';
} else {
document.location.href = 'http://socialpos.com.ar';
}
</script>


I'm not even getting the alert :/

You can see it in http://socialpos.com.ar


More From » browser

 Answers
11
var language = navigator.browserLanguage;


should be



var language = navigator.language || navigator.browserLanguage; //for IE


see my console results:



var language = navigator.browserLanguage;
undefined
language;
undefined
var language = navigator.language;
undefined
language;
en-US


Also please note that this was the first result for a google search: javascript browser language. Google is your friend, and your google-fu is weak. Train it with searches!


[#70353] Sunday, June 29, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
travion

Total Points: 137
Total Questions: 96
Total Answers: 103

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
travion questions
Mon, Dec 16, 19, 00:00, 5 Years ago
Sat, Oct 19, 19, 00:00, 5 Years ago
Fri, Sep 20, 19, 00:00, 5 Years ago
Wed, Nov 14, 18, 00:00, 6 Years ago
Sun, Oct 28, 18, 00:00, 6 Years ago
;