Jump to content

Do code blocks actually run code?

Recommended Posts

Guest Gibran2

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.

Link to comment
  • Replies 4
  • Views 794
  • Created
  • Last Reply

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. 

About me: I've been a SQSP User for 18 yrs. I was invited to join the Circle when it launched in 2016. I have been a Circle Leader since 2017. I don't work for Squarespace. I value honesty, transparency, diversity and good design ♥.
Work: I founded and run SF.DIGITAL, building Squarespace Extensions to supercharge your commerce website. 
Content: Views and opinions are my own. Links in my posts may refer to SF.DIGITAL products or may be affiliate links.
Forum advice is free. You can thank me by clicking one of the feedback emojis below. Coffee is optional.

Link to comment

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)

Link to comment
Guest Gibran2

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.

Link to comment
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.

About me: I've been a SQSP User for 18 yrs. I was invited to join the Circle when it launched in 2016. I have been a Circle Leader since 2017. I don't work for Squarespace. I value honesty, transparency, diversity and good design ♥.
Work: I founded and run SF.DIGITAL, building Squarespace Extensions to supercharge your commerce website. 
Content: Views and opinions are my own. Links in my posts may refer to SF.DIGITAL products or may be affiliate links.
Forum advice is free. You can thank me by clicking one of the feedback emojis below. Coffee is optional.

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.