Skip to content

Instantly share code, notes, and snippets.

@pdincau
Last active August 29, 2015 14:22
Show Gist options
  • Save pdincau/0825ad51adbcd52ee83c to your computer and use it in GitHub Desktop.
Save pdincau/0825ad51adbcd52ee83c to your computer and use it in GitHub Desktop.
amazon links
jQuery(document).ready(function() {
var attributes = {}
attributes["IT"] = 'data-amazon-it';
attributes["GB"] = 'data-amazon-gb';
var url = "http://freegeoip.net/json/ ";
jQuery.getJSON(url, function(data) {
var code = data.country_code;
var links = jQuery('[data-amazon]');
jQuery.each(links, function(index, link) {
var el = jQuery(link);
el.attr('href', el.attr(attributes[code]));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment