Hi, I’m relatively new to Reddit and WordPress. Apologies if this is the wrong place and/or if my wording/terminology is incorrect.
I’m looking to create a popup that is specific to one country. We have visitors from New Zealand and I’d like to have a popup on the HomePage that only opens when they visit from that country.
I have created a simple/test popup and this appears to work, but it’s basically on or it’s not.
I’m using Popup Maker and have inputted the following information at the end of the HTML code in the Edit Popup section.
<!– JavaScript code to detect user’s country and toggle content accordingly –>
<script>
function getCountry(callback) {
var xhr = new XMLHttpRequest();
[xhr.open](https://xhr.open)(‘GET’, ‘[https://ipinfo.io](https://ipinfo.io)’, true);xhr.onload = function () {
if (xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
callback([response.country](https://response.country));
}
};
xhr.send();
}
​
function toggleContentByCountry(countryCode) {
var allowedCountries = \[‘NZ’\]; // Replace with the desired country code(s)
var contentDiv = document.getElementById(‘country-specific-content’);
​
if (allowedCountries.includes(countryCode)) {
contentDiv.style.display = ‘block’; // Show the content
} else {
contentDiv.style.display = ‘none’; // Hide the content
}
}
​
getCountry(function(country) {
toggleContentByCountry(country);
});
</script>
**Please help!**
**Thanks,**
**Gaz**