Jump to content

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
  • Views 4.4k
  • Created
  • Last Reply
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. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

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.

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

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.
 

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but 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.