DomDom282 Posted January 3 Share Posted January 3 (edited) Hi I've added some code to several pages of my website to send visitors only from Australia to an alternate page. (my affiliate links are different for Aussies). I've added the code in the page settings and saved it. It works once but then it doesn't work after that. Also when I try and edit the redirected pages the page partly loads but then goes blank on me unless I use a VPN to show that I'm not in AU. https://www.louisedemasi.com/my-art-supplies Can someone help? Here is the code I've used. See attachment Edited January 25 by DomDom282 added website Link to comment
DomDom282 Posted January 25 Author Share Posted January 25 Can anyone help? Thanks in advance. Link to comment
Solution jpeter Posted January 26 Solution Share Posted January 26 @DomDom282 It looks like your website uses Ajax to load new content in without refreshing the page. Because it's using Ajax to refresh the page, you'll want to wrap your code with window.Squarespace.onInitialize(Y, function() {}) . This will cause the code to re-run on every ajax request. Added new JS code below that should resolve your issue. New JavaScript window.Squarespace.onInitialize(Y, function() { fetch('https://ipapi.co/json/') .then(response => response.json()) .then(data => { if (data.country_code === 'AU') { window.location.href = 'https://www.louisedemasi.com/my-art-supplies-au'; } }) .catch(err => console.log('Error:', err)); }); Be sure to keep the JS code wrapped in <script> tags like so: <script> // Add JS code here </script> Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee! Link to comment
DomDom282 Posted February 26 Author Share Posted February 26 Hi @jpeter Sorry I missed this until today. Thanks so much for the help here. I'll try this now and see how it goes. I'd given up and turned it off and couldn't find help anywhere. I'm glad for the help. Thanks again. Dom Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment