admin管理员组文章数量:1332395
Is it possible to detect the language which is used by the mobile phone to auto switch my mobile site to that corresponding language?
Say for example, My website should display in english to peoples who have english as their language in mobile, similarly for user who have french they should view the site in french.
I have developed the mobile site with jQueryMobile. Its just a static site with HTML & some Js calculations that's all.
Is it possible to detect the language which is used by the mobile phone to auto switch my mobile site to that corresponding language?
Say for example, My website should display in english to peoples who have english as their language in mobile, similarly for user who have french they should view the site in french.
I have developed the mobile site with jQueryMobile. Its just a static site with HTML & some Js calculations that's all.
Share Improve this question edited Mar 15, 2013 at 18:03 ThinkingStiff 65.4k30 gold badges147 silver badges241 bronze badges asked Oct 12, 2011 at 7:45 Logesh PaulLogesh Paul 7,7003 gold badges28 silver badges23 bronze badges 3-
possible duplicate of JavaScript for detecting browser language preference - seems a rather plex problem. Once you have the language code, redirecting is trivial using
location.href
– Pekka Commented Oct 12, 2011 at 7:47 - @pekka thanks for your reply. I'm not targeting desktop browsers because its a mobile only site. I'm trying to detect the language of mobile browser is there any useful information you can help with? – Logesh Paul Commented Oct 12, 2011 at 9:43
- 2 What does detecting the language have to do with mobile vs. desktop? The solutions presented in the duplicate should work in both worlds. Do they not? – Pekka Commented Oct 12, 2011 at 12:18
2 Answers
Reset to default 5You can detect the users language like this:
var l_lang;
if (navigator.userLanguage) // Explorer
l_lang = navigator.userLanguage;
else if (navigator.language) // FF
l_lang = navigator.language;
else
l_lang = "en";
Then go to the language specific page:
location.href = 'www.yourpage./' + l_lang + '.html';
I believe you can not do this with JS.
One of the option is to parse request's "Accept-Laguage", but do this with caution, cause there is could be several with different priority set. This can be done as with some server-side script as well as with apache's config.
本文标签:
版权声明:本文标题:javascript - Detecting the language used by mobile device and auto-switch website to that corresponding language - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742245728a2439351.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论