简体   繁体   中英

Redirect user by their location, not by their browser language

I'm making a website for a company. I have it in 3 languages: English, Norway and Icelandic. I've found out javascripts that redirect user by the language of their browser. Is there any way that I can make the redirect by the location of the user? (like on the mtv.com website). Thank you!

grab this library http://www.localeplanet.com/

you can even use i18n with/without jQuery

You can use Geolocalisation, like using GeoDirection (doesn't require jQuery).

Here's an example of what you could do :

<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>

I could also propose you Reverse Geocoding with the help of Google Geocoding API . It allow you to get a lot of information about the user localisation like is country. After with some condition you could redirect your user at the right page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM