Copy link to clipboard
Copied
I want have two domain names
If a viewer from New Zealand (NZ) visits the Australian site (.com.au), I want the website to detect that they are from New Zealand and redirect them to the NZ domain.
I found this Javascript code on the Business Catalyst KB, however it seems to loop over and over again, even though there are breaks included in the script.
<script language="javascript">
var country = '{module_visitorcountrycode}'; // e.g. var country = US;
switch (country) {
case 'US':
document.location = 'http://us.yourcompany.com';
break;
default:
document.location = 'http://www.yourcompany.com';
break;
};
</script>
I've read that I should use cookies but I'm not sure how to implement that with the above script.
Any help would be much appreciated.
Kind Regards
Brendon
Copy link to clipboard
Copied
That is only a core element Brendon. You need to do a combination of a redirect, conditional statement to check on their location and cookies. There are a few threads on this on the forum already with code, If you do a search you should find one of them I think.
Copy link to clipboard
Copied
Thanks Liam. Maybe something more along these lines then"?
<script language="javascript">
var country = '{module_visitorcountrycode}'; // e.g. var country = NZ;
var countryCookie = document.getcookie(countrycode);
if countryCookie == 'NZ';
switch (country) {
case 'NZ':
document.location = 'http://www.google.com';http://www.demosite.com.au'; // current page;
break;
default:
document.location = 'http://www.demosite.co.nz'; // page to be redirected to;
break;
};
</script>