Reputation:
I have a website and when a user visits, first I'm checking user's browser language by JavaScript code then redirecting user. I have two languages and right now a third language is on the way, but some users may know two languages and maybe they would like to see page language in another language.
For example my browser language is "en" but my native language is Turkish and when I visit my website it's redirecting me to the English page and when I click Turkish flag, it's redirecting me to the English page again. I want to see the page in Turkish also. Sorry for my English and I'm new to JavaScript :)
Mywebsite: www.berkayhelvacioglu.com and my JavaScript code is:
function languageControl() {
var userLang = navigator.language || navigator.userLanguage;
if (userLang == "tr") {
//break;
}
//else if (userLang == "ru" || userLang == "uk") {
// window.location.href = "indexru.aspx";
//}
else {
window.location.href = "indexen.aspx";
}
}
window.onpaint = languageControl();
Thanks for answers but I can't go to Turkish page because my browser language is english and when I click Turkish flag javascript code controls browser language and redirecting me english page again. I have javascript code in index.aspx and index.aspx is Turkish page also. So I want to disable javascript code if I want to go index.aspx instead of indexen.aspx. I hope I explained my self more clear.
Upvotes: 1
Views: 119
Reputation: 9381
document.cookie = "language=RU; expires=Fri, 31 Dec 9999 23:59:59 GMT";
Will create a cookie that won't expire (untill 9999) and you can read the value on every page to serve the right language with
var lang = document.cookie;
Upvotes: 1
Reputation: 141
You can save choosen language in local storage http://www.w3schools.com/html/html5_webstorage.asp
Upvotes: 2