Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search

Adding Custom Javascript to Code Block


Recommended Posts

Site URL: https://flounder-guppy-w6a2.squarespace.com/config/settings/advanced

Hello, I am building a website for a client and they use a custom booking system for their salon. The booking platform has a Javascript code that you can add to your site. I went ahead and added it to a code block and it wouldn't work. I was curious to see if the script was incorrect so I went into my advanced settings and tested it out in the head settings of "code injection" and it worked in the header. For some reason it won't work as a code block on my book now page though. Here is the code.

<script type="text/javascript">daysmart_acc = "48b89c40-9b1b-4a16-a8ac-4a72a4da45dc"; daysmart_iframe_width = 1000; daysmart_iframe_height = 0; daysmart_website_root = "https://plugin.mysalononline.com"; load_in_iframe = "false"; </script><script type="text/javascript" src="https://plugin.mysalononline.com/Scripts/external/bookingplugin.js"></script>

Can someone help me add this to a single page?

Link to comment
  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Insert to Code Block, and DO NOT check "Display source"

Email me if you have need any help (free, of course.). Answer within 24 hours.

How to: Setup password & share url - Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care - Learn CSS - Custom Popup - Testimonial Slider

I'm Tuan, blogger/owner of a free library for children in Vietnam. Helping the community is a hobby. Contact me via email.

Link to comment
1 hour ago, oliviacorin said:

Hi @tuanphan thanks for the response! When I add the javascript in a code block, I can't uncheck Display Source. I can only uncheck it with HTML. 

Can you take screenshot or record a video? You can use Loom.com

Email me if you have need any help (free, of course.). Answer within 24 hours.

How to: Setup password & share url - Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care - Learn CSS - Custom Popup - Testimonial Slider

I'm Tuan, blogger/owner of a free library for children in Vietnam. Helping the community is a hobby. Contact me via email.

Link to comment
1 hour ago, Vadym said:

I can't clear the "display source" checkbox.

A Code Block can be used to

  • display code (JavaScript, CSS, HTML, Plain Text - with 'Display Source' checked, or
  • inject code- with 'Display Source' unchecked. 

Display Source will always checked for CSS, JavaScript, and Plain Text because you cannot add these directly to a web page. This is the case with any web page, not just on Squarespace. 

If you want JavaScript to run on a web page, you must first place it within some HTML script tags. By this I mean that you must add <script> at the beginning and </script> at the end. The <script> tags are HTML and they tell the browser to expect some code (otherwise known as 'script').

When you have added these (as it appears you already have), the code is considered HTML. For this reason, select HTML from the dropdown, instead of JavaScript.

When HTML is selected, you will be able to uncheck Display Source and the code should work, at least whilst logged out.

Edited by paul2009

sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi! I'm Paul, an independent Squarespace Consultant since 2007 and founder of SF Digital, building the features that Squarespace didn't include. Our mini-extensions allow you to pick dates in any format, show prices in other currencies, take orders without payment or improve your cartI value honesty, integrity, transparency and respect . Links in my posts may refer to SF Digital products or may be affiliate links.

Link to comment

Hi @paul2009 thanks for the response! That worked to change it to HTML, but now I am getting that I can only preview it in safe mode because it is embedded. When I view it in safe mode, it still shows up as a slider. Here are some screenshots of what I'm seeing. Do you know why or if there is somthing wrong with the code? I am not familiar with the booking system they use, so it's hard to know what to change.

Book Now — Your Site Title - Google Chrome 4_9_2020 5_32_03 PM.png

Book Now — Your Site Title - Google Chrome 4_9_2020 5_32_18 PM.png

Link to comment

@oliviacorin It's normal for code is disabled during login. It's much better to test it whilst logged out, so a private or incognito window works best for this.

If the code itself is causing problems, the first thing to try is speaking to the company who supplied it. If you or your client is paying to use their service, I'd hope that they are able to give you some advice.

That said, if you have hit a brick wall and need the community to help, we will need to be able to reach the page on the site. The site is currently private so for us to see the issue first-hand, you'll need to set a site password and tell us what it is.
 

sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi! I'm Paul, an independent Squarespace Consultant since 2007 and founder of SF Digital, building the features that Squarespace didn't include. Our mini-extensions allow you to pick dates in any format, show prices in other currencies, take orders without payment or improve your cartI value honesty, integrity, transparency and respect . Links in my posts may refer to SF Digital products or may be affiliate links.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...