Skip to content

Commit

Permalink
Add function checker and fallback support
Browse files Browse the repository at this point in the history
  • Loading branch information
irazasyed committed Mar 29, 2014
1 parent 823d2ff commit b62be9a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion geoip-target-redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@
// ------------------------------------------------------
// DON'T EDIT THE BELOW CODE UNLESS REQUIRED
// ------------------------------------------------------
var visitorCountryCode = geoip_country_code();
/**
* Checks if geoip_country_code() was loaded from the MaxMind JS API.
* This prevents the script from breaking due to undefined error thrown.
*
* @return {String|Boolean} ISO 3166-1 - Alpha-2 Country Code or False.
*/
function visitor_country_code() {
// Checks if geoip_country_code() function was loaded from the API.
if(typeof geoip_country_code == 'function') return geoip_country_code();
// Failed to load geoip_country_code() function, return FALSE.
console.log('geoip_country_code() failed to load, Check API!');
return 'All';
}
var visitorCountryCode = visitor_country_code();
var redirectURL = target[visitorCountryCode];
if(redirectURL == null) redirectURL = target.All;
window.top.location.href = redirectURL;
Expand Down

0 comments on commit b62be9a

Please sign in to comment.