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

Do code blocks actually run code?

Question

Hello,

I'm new to squarespace.

I'm trying to use the code block feature to run some very simple Javascript, but I'm not able to. The script is like this:

<script>

alert('hello');

</script>

This is supposed to display a popup with 'hello' in it. But it doesn't.

Reading the article on code blocks:

https://support.squarespace.com/hc/en-us/articles/206543167-Code-Blocks

...tells me that Javascript in code blocks is a premium feature only.

This *might* explain why it's not working for me, but I'm also wondering if I'm misunderstanding the point of code blocks. The article describes the point of code blocks as "rendering code". So I'm wondering if it is only meant to display code on the screen, NOT for running code. (This would explain why my Javascript is always displayed on the screen and I don't have the option to hide it).

Thanks.

Share this post


Link to post

4 answers to this question

Recommended Posts

  • 0

The code will run if HTML is selected as the format, and ‘Display Source’ is not checked. If the site is live, JavaScript will not run on personal plans. You may need to view the site whilst logged out to see the code working. 


World-class Squarespace Developer and Squarespace Circle Leader with a strong reputation on the Squarespace Forum.
I'm trusted by hundreds of Squarespace users worldwide, including designers, freelancers, business owners and big agencies.

I can tackle anything from small tweaks to full websites and I'm available for short and long bookings (min. 1 hour).
Book via my website giving as much notice as possible. Note that I'm usually booked six weeks in advance for jobs longer than an hour.
Prebuilt Squarespace Extensions
Custom Squarespace Extensions: Tell me about the functionality you need

 

Share this post


Link to post
  • 0

In addition to what Paul mentioned, you may also want to disable AJAX loading if your template supports it and has it enabled. The innerHTML() method by which body content is dynamically updated may cause scripts to misbehave (or rather, not behave at all).


If a response helped you out, send a 'Like' 👍 (bottom-right) and/or 'Upvote' vote.jpg.c260784ece77aec852b0e3049c77a607.jpg (top-left)

Share this post


Link to post
  • 0

Thanks both.

I'm currently on a personal plan, so that's probably why the script isn't running. Even logging out and visiting my site won't run the script.

I don't think I'm on a template. When I follow the instructions at this link:

https://support.squarespace.com/hc/en-us/articles/115005308187

I see no template. It just says:

Squarespace 
Version 7.1

And furthermore, I'm not seeing a "site styles" in the design menu as this link suggests there should be:

https://support.squarespace.com/hc/en-us/articles/115000253288-Ajax-loading

...and I'm guessing this is because I'm not on a template.

Share this post


Link to post
  • 0
41 minutes ago, Gibran2 said:

I'm currently on a personal plan, so that's probably why the script isn't running

That's exactly right.


World-class Squarespace Developer and Squarespace Circle Leader with a strong reputation on the Squarespace Forum.
I'm trusted by hundreds of Squarespace users worldwide, including designers, freelancers, business owners and big agencies.

I can tackle anything from small tweaks to full websites and I'm available for short and long bookings (min. 1 hour).
Book via my website giving as much notice as possible. Note that I'm usually booked six weeks in advance for jobs longer than an hour.
Prebuilt Squarespace Extensions
Custom Squarespace Extensions: Tell me about the functionality you need

 

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...