• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Country Detection for URL redirect (Shopping Cart)

Participant ,
Mar 17, 2014 Mar 17, 2014

Copy link to clipboard

Copied

I want have two domain names

www.demo.com.au

www.demo.co.nz

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

TOPICS
eCommerce

Views

600

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 17, 2014 Mar 17, 2014

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 17, 2014 Mar 17, 2014

Copy link to clipboard

Copied

LATEST

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines