Jump to content

Page Header Code Injection Causing All Page Buttons React

Go to solution Solved by HoaLT,

Recommended Posts

Posted (edited)

Hello All - An interesting Issue here:

I have a Page Header Code Injection that triggers a button to open a pop-up scheduling calendar, and it works great here: 
https://www.coorlasarch.com/contact

But when I place the same code injection on another page, all buttons on the page are opening the scheduling calendar here:
https://www.coorlasarch.com/

Is there a way to only target the "Book Now" Button on the home page to open the scheduling calendar?  The Button's Link is set to URL #google-scheduler

image.thumb.png.95814591f711d1958f07260ed560afd9.png

 

 Code injection for reference:

<style>
div.code-block {
    visibility: hidden;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
$(document).on('click', '.button-block a', function(event) { 
    event.preventDefault(); 
    $('.code-block button').click(); 
});
</script>

 

Thank you in advance,

Stephen

Edited by CoorlasArchitecture
Submitted prematurely
  • CoorlasArchitecture changed the title to Page Header Code Injection Causing All Page Buttons React
  • Solution
Posted

Change your code to

<script>
$(document).on('click', '#collection-615ba6582ee8b96aab3a717d .button-block a[href="#google-scheduler"]', function(event) { 
    event.preventDefault(); 
    $('.code-block button').click(); 
});
</script>

to run code only on home page with the button whose href is #google-scheduler

Press 👍  or mark my comment as solution if you find my sharing useful

🆒 Squarespace pinchzoom lightbox plugin (affiliate link)

👁‍🗨 360 degree photo viewer (affiliate link)

📑 Squarespace embed PDF popup (affiliate link)

Posted

Thank you for your response and efforts on this. Is this code a page header injection or code in the actual section?

When added to the page header it reveals a button that is created by a section code I failed to mentioned previously:

<!-- Google Calendar Appointment Scheduling begin -->
<link href="https://calendar.google.com/calendar/scheduling-button-script.css" rel="stylesheet">
<script src="https://calendar.google.com/calendar/scheduling-button-script.js" async></script>
<script>
(function() {
  var target = document.currentScript;
  window.addEventListener('load', function() {
    calendar.schedulingButton.load({
      url: 'https://calendar.google.com/calendar/appointments/schedules/AcZssZ1pO8pVcGaBrfKVYpLabMPR24pc7r6TJ4W-Cmb2PHIZt5xo_H8GrOXLQE0kSce8K8nGZMAe5Soy?gv=true',
      color: '#b28e74',
      label: 'Book',
      target,
    });
  });
})();
</script>
<!-- end Google Calendar Appointment Scheduling -->

 

Posted

Thank you, I added the "visibility: hidden;" code prompt from the original page header code injection and now it works perfectly:

<style>
div.code-block {
    visibility: hidden;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
$(document).on('click', '#collection-615ba6582ee8b96aab3a717d .button-block a[href="#google-scheduler"]', function(event) { 
    event.preventDefault(); 
    $('.code-block button').click(); 
});
</script>

Thank you so much for your attention to this - Greatly appreciated!

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.