Jump to content

Embedded code not loading when page loads

Recommended Posts

To begin I must say I have no real experience coding, so if you need more information or something different, please ask! 

I have been using three different third party widgets (like affiliates or hover maps) and have been injecting their code into the website. My problem is when you load the website, the things with code don't load until you refresh the page. 

Example 1: On the home page, there is supposed to be a map that shows up before the slide gallery underneath it. If you hit refresh the map shows up, but it doesn't show up when you first go to the page. 

https://www.howeverbighoweversmall.com

Example 2 & 3: Here on the product page I want to have the affiliate links work under Book Your Activity or Book Your Accommodation. Again, they only work when you refresh the page. Is there something I can do from my Squarespace editor or is this something wrong with all of the code?

https://www.howeverbighoweversmall.com/get-your-itinerary/8-days-in-tuscany

Here is the code for Booking.com for example:

<ins class="bookingaff" data-aid="1890417" data-target_aid="1890417" data-prod="map" data-width="100%" data-height="590" data-lang="ualng" data-dest_id="0" data-dest_type="landmark" data-latitude="43.7679178" data-longitude="11.2523792" data-landmark_name="Cape Town" data-mwhsb="0" data-address="Cape Town">
    <!-- Anything inside will go away once widget is loaded. -->
        <a href="//www.booking.com?aid=1890417">Booking.com</a>
</ins>
<script type="text/javascript">
    (function(d, sc, u) {
      var s = d.createElement(sc), p = d.getElementsByTagName(sc)[0];
      s.type = 'text/javascript';
      s.async = true;
      s.src = u + '?v=' + (+new Date());
      p.parentNode.insertBefore(s,p);
      })(document, 'script', '//aff.bstatic.com/static/affiliate_base/js/flexiproduct.js');
</script>

Thank you in advance!!

Link to comment
  • 2 months later...
  • 4 months later...

Hi there! I'm glad I found this post. I have the same issue now with this code from Tryinteract:

<div id="interact-5eda865db27ec100144ca6e2"></div><script type="text/javascript">var app_5eda865db27ec100144ca6e2;(function(d, t){var s=d.createElement(t),options={"appId":"5eda865db27ec100144ca6e2","width":"800","height":"800","async":true,"host":"quiz.tryinteract.com","mobile":true,"footer":"show"};s.src='https://i.tryinteract.com/embed/app.js';s.onload=s.onreadystatechange=function(){var rs=this.readyState;if(rs)if(rs!='complete')if(rs!='loaded')return;try{app_5eda865db27ec100144ca6e2=new InteractApp();app_5eda865db27ec100144ca6e2.initialize(options);app_5eda865db27ec100144ca6e2.display();}catch(e){}};var scr=d.getElementsByTagName(t)[0],par=scr.parentNode;par.insertBefore(s,scr);})(document,'script');</script>

Does anybody know how to wrap up that one to work fine? Thanks so much as I also don't know anything about coding.

Best, Johannes

Edited by Johster
Link to comment
  • 1 year later...

Hi, I'm also having this issue but the solution of wrapping it in 

On 1/12/2020 at 7:24 AM, brandon said:

window.Squarespace.onInitialize(Y, function() { //Your code here... });

doesn't work for me as the code block doesn't execute any javascript unless refreshed. Can't even log to the console, so the function is not bound (I'm assuming the onInitialize function is an event binding, I'm only moderately proficient with javascript). Could you repost what you had linked at https://forum.squarespace.com/topic/3077-choosing-an-implementation-method-for-custom-javascript-on-ajax-loading-templates/?do=findComment&comment=17885 @brandon ? Still can't access that link.

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...

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.