yasmikash Posted November 7, 2019 Share Posted November 7, 2019 (edited) Hello there, I have written a javascript with some jQuery to call an api and get some data to be rendered when a user clicks on a specific page. I have put this code inside the header of code injection section. But the problem is the script seems to execute only when user access the site the first time, not when they are accessing that specific page. Can anyone be able to help me out to have a workaround to this problem? Edited November 7, 2019 by yasmikash Link to comment
colin.irwin Posted November 7, 2019 Share Posted November 7, 2019 Here's what you need to do. First, wrap your code as follows <script> window.Squarespace.onInitialize(Y, function(){ // Your code here }); </script> This will execute the code on each page load. Next, you may need to modify the code so that it only runs for the specific page. You do this by testing the body tag for the presence of the specific collection id. Ciodensky, yasmikash and Sergio 3 If you're looking for a Squarespace Developer, drop me a line. Link to comment
yasmikash Posted November 8, 2019 Author Share Posted November 8, 2019 20 hours ago, colin.irwin said: Here's what you need to do. First, wrap your code as follows <script> window.Squarespace.onInitialize(Y, function(){ // Your code here }); </script> This will execute the code on each page load. Next, you may need to modify the code so that it only runs for the specific page. You do this by testing the body tag for the presence of the specific collection id. Thanks! This really helped me!! Link to comment
Ciodensky Posted November 5, 2021 Share Posted November 5, 2021 On 11/7/2019 at 7:01 PM, colin.irwin said: Here's what you need to do. First, wrap your code as follows <script> window.Squarespace.onInitialize(Y, function(){ // Your code here }); </script> This will execute the code on each page load. Next, you may need to modify the code so that it only runs for the specific page. You do this by testing the body tag for the presence of the specific collection id. Hi @colin.irwin, I am wondering if this code works for my case? I am trying to trigger the script on the product-varian select (or shall we say combobox) provided by template. 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