0

I've got an interesting one here..

The scenario

I have a Squarespace website that doesn't load the pages, it just swaps out the content (think Angular routing) and on this website I have a Typeform embedded via an iframe.

Because the page doesn't "reload" when a new page is changed, the Typeform doesn't load the iframe. It needs to be triggered by a page reload, so naturally i added some JS to do this

(function(){
    window.location.reload();
    stop();
})();

However, again much like the form, JS isn't being triggered because the page isn't reloading, it's swapping content. I confirmed this by reloading the page and the line above worked.

The question

How on earth am I supposed to reload the page if JS isn't loaded on the page because of the way the page is rendered?

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103

1 Answers1

3

Your question is very closely related to this one, and likely shares the same or similar answer.

You'll probably need to either disable AJAX in the style editor or there are other options that have been offered such as:

window.Squarespace.onInitialize(Y, function() {
  // do stuff
});

or

window.addEventListener("mercury:load", function(){
   // do stuff
});

or

new MutationObserver(function() {
  // do stuff
}).observe(document.body, {attributes:true, attributeFilter:["id"]});
Brandon
  • 3,572
  • 2
  • 12
  • 27
  • Thanks for this, unfortunately it doesn't seem to work anymore (per my testing and users in this thread: https://answers.squarespace.com/questions/152385/jquery-header-code-injection-not-running-after-ind.html) Disable Ajax works, but I'd prefer to not do that as I have some lengthy image-heavy pages where ajax seems like it'd be beneficial (since it only loads the content in the viewport, from what I understand) – Will Ryan Jul 15 '17 at 20:33
  • I recently (within the last few days) tested the `mercury:load` solution and it did work for me, so if we're both correct, then it would appear that there are additional factors in play. Also note that this solution used to exist at the link you provided, but was removed due to the user's posts being removed from the forum. Therefore the forum post to which you linked no longer reads quite as it should because posts that were part of the conversation have been removed. – Brandon Jul 15 '17 at 22:32