Website that recognizes user's location/IP & changes lang. based on that

前端 未结 6 566
抹茶落季
抹茶落季 2020-12-13 22:40

title is pretty clear.

My websites consists of both English-written and Spanish-written versions. You can go to the main site, which is in Spanish, by clicking http:

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 23:06

    Rather than detecting the location of IP address (often unreliable due to NAT and proxying) you could check the default language the browser is set to. There are JQuery plugins to support this, such as http://keith-wood.name/localisation.html, or use server-side code to read the HTTP request header "HTTP_ACCEPT_LANGUAGE" to determine if you want to show the ES or EN site.

提交回复
热议问题