Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0
yasmikash

Executing my javascript code only on a specific page

Question

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 by yasmikash

Share this post


Link to post

2 answers to this question

Recommended Posts

  • 0

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. 


Please hit LIKE to share your appreciation of posts that are helpful or useful. 

The like button is somewhere over thereover-there.jpg

Of course, Likes don't pay the bills.. If you're looking for a Squarespace Developer you can hire me here

Share this post


Link to post
  • 0
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!!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...