Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Redirecting...</title>
<!------------------------------------------------------------------
MaxMind's GeoIP JavaScript API
@URL: http://dev.maxmind.com/geoip/javascript
-------------------------------------------------------------------->
<script src="//j.maxmind.com/app/country.js" charset="ISO-8859-1"></script>
<script>
// ----------------------------------------------------------------
// A small snippet for geo-redirection using MaxMind's GeoIP API.
// Add your targeted country's "ISO 3166-1 - Alpha-2" code and
// redirect URL to the "target" array object.
// ----------------------------------------------------------------
// Example: target['us'] = "http://domain.com";
// ----------------------------------------------------------------
// Country Codes can be found @( Wikipedia - http://bit.ly/nWBMYz )
// See Column: "Alpha-2 Code"
// ----------------------------------------------------------------
(function(){
var target = new Array(); // Create a new target Array.
// Example Code:
target['All'] = "http://domain.com/"; // Redirects' Non-targeted/other visitors to this URL.
target['US'] = "http://domain.us/"; // Redirects' US Visitors to this URL.
target['GB'] = "http://domain.uk/"; // Redirects' UK Visitors to this URL.
target['CA'] = "http://domain.ca/"; // Redirects' Canadian Visitors to this URL.
// ------------------------------------------------------
// DON'T EDIT THE BELOW CODE UNLESS REQUIRED
// ------------------------------------------------------
var visitorCountryCode = geoip_country_code();
var redirectURL = target[visitorCountryCode];
if(redirectURL == null) redirectURL = target['All'];
if(redirectURL) window.top.location.href = redirectURL;
})();
</script>
</head>
<body>
<p>Please wait...</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.