根据用户的位置而不是浏览器语言重定向用户

Redirect user by their location, not by their browser language

本文关键字:用户 浏览器 语言 重定向 位置      更新时间:2023-09-26

我正在为一家公司制作一个网站。我有三种语言:英语、挪威语和冰岛语。我发现了通过浏览器语言重定向用户的java脚本。有什么方法可以通过用户的位置进行重定向吗?(比如在mtv网站上)。非常感谢。

获取此库http://www.localeplanet.com/

您甚至可以使用带有/不带有jQuery 的i18n

您可以使用Geolocalization,就像使用GeoDirection一样(不需要jQuery)。

这里有一个你可以做的例子:

<script language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesLocationCode,GeobytesCode,GeobytesInternet"></script>
<script language="Javascript">
if(typeof(sGeobytesLocationCode)=="undefined"
   ||typeof(sGeobytesCode)=="undefined"
   ||typeof(sGeobytesInternet)=="undefined")
{
   // Something has gone wrong with the variables, so set them to some default value,
   // maybe set a error flag to check for later on.
   var sGeobytesLocationCode="unknown";
   var sGeobytesCode="unknown";
   var sGeobytesInternet="unknown";
}
if(sGeobytesLocationCode=="CAQCMONT")
{
   // Visitors from Montreal would go here
   window.open("enter Montreal URL here");
}else if(sGeobytesCode=="QC")
{
   // Visitors from Quebec would go here
   window.open("enter Quebec URL here");
}else if(sGeobytesInternet=="CA")
{
   // Visitors from Canada would go here
   window.open("enter Canada URL here");
}
</script>

我还可以建议您借助Google Geocoding API进行反向地理编码。它可以让你获得很多关于用户本地化的信息,就像is country一样。在满足某些条件后,您可以在右侧页面重定向用户。