elderlyman Posted June 11, 2020 Share Posted June 11, 2020 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? Link to comment
RyanDejaegher Posted June 11, 2020 Share Posted June 11, 2020 @elderlyman what JavaScript are you trying to add? This is actually the way it's supposed to work Philadelphia, PA 👉 Squarespace Tutorials Chat/Message on FB Messenger for quickest response: https://m.me/dejaegherryan Link to comment
elderlyman Posted June 16, 2020 Author Share Posted June 16, 2020 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
Solution paul2009 Posted June 17, 2020 Solution Share Posted June 17, 2020 (edited) 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. Edited June 17, 2020 by paul2009 About: Squarespace Circle Leader since 2017. I value honesty, transparency, diversity and great design ♥.Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™. Content: Links in my posts may refer to SF Digital products or may be affiliate links. Catch up on all the release notes and announcements 2023 [for Circle members only]. There's a public version here too!If I helped, you can thank me by clicking one of the emojis below. If you prefer, you can buy me a coffee.Improve your online store with our extensions. Link to comment
TempusInfernus Posted July 18, 2020 Share Posted July 18, 2020 (edited) 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. Edited July 18, 2020 by TempusInfernus expanding 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment