Jump to content

Why can't I uncheck the Display Source box when using JavaScript in a code block?

Recommended Posts

Site URL: http://bostonbiketaxi.com

When I attempt to write some code in a code block using JavaScript, the Display Source option grays out and prohibits me from checking/unchecking.  So I am effectively prohibited from using JavaScript in a code block.  The option to check/uncheck the Display Source box works as expected when HTML is selected, but not for JavaScript.  What could be happening here?

 

 

1.png

2.png

3.png

Link to comment
  • Replies 4
  • Views 1.3k
  • Created
  • Last Reply

Thanks @RyanDejaegher.  I should have read the docs further to see that display is always checked for JS.  Though I still don't understand why the Squarespace feature would be designed this way.  Why would there be no option to actually run JavaScript in a code block, only display it?  Yet the HTML can actually run be run or be displayed in a code block? 

Link to comment
16 hours ago, elderlyman said:

Though I still don't understand why the Squarespace feature would be designed this way.  Why would there be no option to actually run JavaScript in a code block, only display it?

A Code Block can be used for two reasons:

  • to display code for others to read (by checking the Display Source option) and,
  • to add HTML to a webpage.

Because web pages are built with HTML, to add functional code, you must first format it as HTML. JavaScript can be added to a web page, but you must select HTML as the code type, and then insert the JavaScript between <script> and </script> tags.

It's the same for CSS. To add it using a Code Block, you must insert it between <style> and </style> tags - although Squarespace has a better solution for CSS.

 

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
  • 1 month later...

You can run javascript in the code block - just make sure you are not still in edit mode. (when you flip to preview mode it runs - for example a widget embed will show up)  I made this mistake struggling for about 2 hours the other day and when I figured it out, I wanted to smash my head into the desk for an equal amount of time. 

I'm more of a designer than a developer, but I know some HTML, CSS, and Javascript, and PHP, but I would not describe myself as good at any of them. I know just enough to get things to work the way I want with a little help sometimes, even if it takes hours and hours of burning time.

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.