【问题标题】:Redirect user by their location, not by their browser language按用户的位置而不是浏览器语言重定向用户
【发布时间】:2014-04-10 14:45:17
【问题描述】:

我正在为一家公司制作网站。我有 3 种语言版本:英语、挪威语和冰岛语。我发现了通过浏览器语言重定向用户的 javascript。有什么方法可以通过用户的位置进行重定向? (例如在 mtv.com 网站上)。谢谢!

【问题讨论】:

  • 这通常是个坏主意。仅仅因为旅行者可能某个国家/地区并不意味着他希望以该语言提供服务。
  • 这是一家标牌制作公司,因此与企业对企业的关系更加密切。我认为这对这个项目很有用。

标签: javascript jquery html redirect


【解决方案1】:

抓住这个图书馆http://www.localeplanet.com/

你甚至可以使用 i18n 带/不带 jQuery

【讨论】:

  • 你觉得哪个更好?我知道可能与 Google 存在一些冲突。现在我将拥有 3 个 .html 文件,但客户端将拥有 3 个不同的域。所以我想,如果挪威客户端将访问 .com 域以重定向到 .no 网站。
【解决方案2】:

您可以使用地理定位,例如使用 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>

【讨论】:

  • 感谢您的回复。我已经看到了这个选项,但我不喜欢他们每 50 个重定向中的 1 个都会弹出广告。
【解决方案3】:

我还可以在Google Geocoding API 的帮助下向您推荐Reverse Geocoding。它使您可以获取有关国家/地区等用户本地化的大量信息。在某些条件下,您可以将您的用户重定向到正确的页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    相关资源
    最近更新 更多