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. 


If a response has helped you, please give thanks using the  like-20-mag.png.3997345d620e40b4760b5d7a667cad54.png button.
Need personalised help? I'm a professional Developer who works with Designers internationally. You can book me via my company's website. www.sf.digital

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.


If a response has helped you, please give thanks using the  like-20-mag.png.3997345d620e40b4760b5d7a667cad54.png button.
Need personalised help? I'm a professional Developer who works with Designers internationally. You can book me via my company's website. www.sf.digital

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