ksachse Posted May 17 Posted May 17 Hello! I'm attempting to fix the Close button on a Squarespace-provided Cookies Banner by changing the 'aria-label' properties. I added the below JS to Code Injection > Footer, but still running into same issue on PageSpeed Insights. This is the affected website Any thoughts? <script> // accessibility cookies banner script window.Squarespace.onInitialize(Y, function () { document.querySelectorAll(".sqs-cookie-banner-v2-accept") .forEach(el => el.setAttribute("aria-label", "Accept")); document.querySelectorAll(".sqs-cookie-banner-v2-cta") .forEach(el => el.setAttribute("aria-label", "Accept")); }); </script> Kaila S Shopify Partner, Squarespace Circle Member & MailChimp Expert yumari digitalwebsites · email campaigns · ads · social media · graphic design
jpeter Posted May 18 Posted May 18 @ksachse Looks like you're code may be running to soon by the time the banner initialized, so you can wrap your code in a setTimeout and delay execution. Here's the updated code with a DELAY that will run your code after 500 milliseconds. Feel free to increase or decrease the DELAY value: <script> // accessibility cookies banner script window.Squarespace.onInitialize(Y, function () { const DELAY = 500; setTimeout(() => { document.querySelectorAll(".sqs-cookie-banner-v2-accept") .forEach(el => el.setAttribute("aria-label", "Accept")); document.querySelectorAll(".sqs-cookie-banner-v2-cta") .forEach(el => el.setAttribute("aria-label", "Accept")); }) }, DELAY); </script> Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!
ksachse Posted May 20 Author Posted May 20 Many thanks @jpeter I experimented between 10 milliseconds and 6000 milliseconds and no luck. Is there a tool that can be used to know what the sweet spot may be? Kaila S Shopify Partner, Squarespace Circle Member & MailChimp Expert yumari digitalwebsites · email campaigns · ads · social media · graphic design
Solution paul2009 Posted May 21 Solution Posted May 21 On 5/17/2024 at 5:07 PM, ksachse said: I'm attempting to fix the Close button on a Squarespace-provided Cookies Banner by changing the 'aria-label' properties. @ksachse YUI isn't loaded so you'll want to detect the page load in a different way. For example: <!----- Accessibility cookies banner script ------> <script> window.addEventListener("load", function() { document.querySelectorAll(".sqs-cookie-banner-v2-accept") .forEach(el => el.setAttribute("aria-label", "Accept Cookies")); }); </script> As an aside, I see that this site only has opt-in enabled. If you're concerned about compliance in Europe, I recommend adding the opt-out feature so that visitors have the option to reject cookies too 🙂. Did this help? Please give feedback by clicking an icon below ⬇️ ksachse 1 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.
ksachse Posted May 21 Author Posted May 21 6 hours ago, paul2009 said: @ksachse YUI isn't loaded so you'll want to detect the page load in a different way. For example: <!----- Accessibility cookies banner script ------> <script> window.addEventListener("load", function() { document.querySelectorAll(".sqs-cookie-banner-v2-accept") .forEach(el => el.setAttribute("aria-label", "Accept Cookies")); }); </script> As an aside, I see that this site only has opt-in enabled. If you're concerned about compliance in Europe, I recommend adding the opt-out feature so that visitors have the option to reject cookies too 🙂. Did this help? Please give feedback by clicking an icon below ⬇️ Thank you very much sir!! You are a gentleman and a scholar. Kaila S Shopify Partner, Squarespace Circle Member & MailChimp Expert yumari digitalwebsites · email campaigns · ads · social media · graphic design
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment