[英]Redirect user by their location, not by their browser language
我正在为一家公司建立网站。 我有3种语言的版本:英语,挪威和冰岛语。 我发现了通过用户的浏览器语言重定向用户的JavaScript。 有什么方法可以通过用户的位置进行重定向? (例如mtv.com网站)。 谢谢!
抓住这个图书馆http://www.localeplanet.com/
您甚至可以在有/没有jQuery的情况下使用i18n
您可以像使用GeoDirection (不需要jQuery)一样使用Geolocalisation。
这是您可以做什么的示例:
<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进行 反向地理 编码 。 它使您可以获取有关国家/地区用户本地化的大量信息。 遇到某种情况后,您可以在正确的页面上重定向用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.