Jump to content

[Share] Click Button Block - Play Audio & Open New Page

Recommended Posts

Posted

Description

  •  Click button (button block) will play an audio
  • After 1 second, will open new page

#1. First, use this code to Code Injection > Footer (or Page Header Injection)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).on('click', 'div.button-block a', function (e) {
    e.preventDefault();
    let audio = new Audio('https://www.w3schools.com/tags/horse.ogg');
    audio.play(); 
    setTimeout(() => {
        window.location.href = $(this).attr('href'); 
    }, 1000);
});
</script>

image.png.3d69878a2fb9cb5039fc973c3e568fbd.png

#2. Replace sample audio with new audio url. You can use mp3 file

image.png.fc36d083b34cf1627ed8ff7dabe9486f.png

You can change 1 second here (1000 = 1 second)

image.png.c9ec3b1423677b994a09b9a62506f180.png

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!)

  • Replies 1
  • Views 63
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

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.