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. 


sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi, I'm Paul, founder of SF Digital, a specialist company building the features that Squarespace didn't include
I am a Squarespace Developer and Squarespace Circle Leader with a
strong reputation on the Squarespace Forum. I'm trusted by thousands of Squarespace users worldwide, including designers, freelancers, business owners and agencies. My extensions add capabilities to Squarespace websites around the globe. They include the Enquiry Form ExtensionDatepicker Extension and Age Verification ExtensionNeed a custom Squarespace extension? Tell me about the functionality you need. Note that some links in my posts may be affiliate links. Book a Squarespace Expert when you need help.

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.


sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi, I'm Paul, founder of SF Digital, a specialist company building the features that Squarespace didn't include
I am a Squarespace Developer and Squarespace Circle Leader with a
strong reputation on the Squarespace Forum. I'm trusted by thousands of Squarespace users worldwide, including designers, freelancers, business owners and agencies. My extensions add capabilities to Squarespace websites around the globe. They include the Enquiry Form ExtensionDatepicker Extension and Age Verification ExtensionNeed a custom Squarespace extension? Tell me about the functionality you need. Note that some links in my posts may be affiliate links. Book a Squarespace Expert when you need help.

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