1

After a day off being stuck, about why on earth i wouldnt get my jquery custom code to work on SquareSpace template; i found that this is due to the AJAX loading.

So yes, the script runs when: - U go directly to the page via the URL. - U refresh the page after landing on it.

I've find that i must disable Ajax load on Design Panel which is not possible with my client request, i must have the ajax load enabled for smooth navigation.

Is there any code that i can add to display my content created with code injection?

Template : Shift

Website : Link here

Thanks

RedaZZ
  • 25
  • 4
  • Information such as what template you are using and a link to the site itself may be helpful to others in proposing a solution. – Brandon Nov 27 '17 at 13:36
  • Hi Brando this issue is common to all the templates with ajax load my template is Shift here is the link https://rudolf-buchbinder-2.squarespace.com/timeline/ – RedaZZ Nov 27 '17 at 14:39
  • The issue is common to templates with the AJAX-loading option. However, the solution varies by template family, which is why that is important information. The template ID in the source code of your site indicates you are using a template from the Brine/Wright family (not Shift, but the possibility exists I am incorrect). Therefore, this answer ought to work: https://stackoverflow.com/a/42604055/5338581 – Brandon Nov 27 '17 at 14:50
  • Hi @Brandon thank you for your answer it helped me solve my issue, i've tried this code on other website before didn't know that works for some templates but not all of them. – RedaZZ Nov 27 '17 at 17:18
  • Glad to help. Consider up-voting said answer if it helped you. – Brandon Nov 27 '17 at 17:27
  • Hi @Brandon of course but i don't have where to up-vote your answer because it's add as a comment i think? – RedaZZ Nov 28 '17 at 08:43
  • I'm referring to the answer referenced: stackoverflow.com/a/42604055/5338581 – Brandon Nov 28 '17 at 13:59
  • Possible duplicate of [JavaScript only being called once in Squarespace](https://stackoverflow.com/questions/54492245/javascript-only-being-called-once-in-squarespace) – Brandon May 13 '19 at 18:28

1 Answers1

6

Squarespace uses their own AJAX loader called mercury. https://github.com/Squarespace/squarespace-mercury To hook into it try adding the following event listener.

document.addEventListener('DOMContentLoaded', customCode);
window.addEventListener('mercury:load', customCode);

function customCode(){
   console.log('woohoo!');
}
Lex
  • 4,749
  • 3
  • 45
  • 66
Paul
  • 61
  • 1
  • 4