Here is the code that I have. This one works but it only checks for one location at a time.
<script>
jQuery.ajax( {
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function(location) {
// If the visitor is browsing from UK.
if (location.country_code === 'UK') {
// Redirect him to the UK Store store.
window.location.href = 'http://www.domain.co.uk';
}
}
} );
</script>
Here is what I've tried:
<script>
jQuery.ajax( {
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function(location) {
// If the visitor is browsing from UK, Germany, France, and Sweden.
if (location.country_code === 'UK || DE || FR || SE') {
// Redirect him to the UK Store store.
window.location.href = 'http://www.domain.co.uk';
}
}
} );
</script>
But it doesn't work. I'm not terribly experienced with JavaScript so I'm not 100% sure how to go about making this work. I assume I would be able to create a variable (an array, rather) named something along the liens of "countries" and make it equal to those countries like var countries = ["UK", "DE", "FR", "SE"]
and then have the script check to see if the person's current location is one of those countries in the array. However, I don't know how to do that.
Help!
Checks for a string 'UK || DE || FR || SE' and will never be true in your case.
This will work:
Another aproach would be, as you described, making an array and check if the entry exists. This would be like:
DUMMYCODE: