FROM CACHE - en_header

How to enter javascript function in Button link box

jfkScollar
Shopify Partner
11 0 0

We would like to call a Javascript function using the Image with Text Overlay section's Button link. The text box for the link entry does not appear to allow such a javascript call to be entered. See image below. Any suggestions you have would be much appreciated. 

John

jfkScollar_0-1633560126345.png

 

Replies 3 (3)
diego_ezfy
Shopify Partner
2791 526 714

@jfkScollar 

You can't. You'll need to create an event listener on that button and, whenever it's clicked, you can call the function you wish. 

Kind regards,
Diego

jfkScollar
Shopify Partner
11 0 0

Hi @diego_ezfy

Thank you for your response.

As the Button's class is generic and there are multiple Buttons that have the same class, how is one to assign an unique ID to the button to create an event listener on that button?

Thanks,

John

jfkScollar
Shopify Partner
11 0 0

Hi @lucas05021,

I haven't. Thanks for asking. Hoping someone has and can post it here. 

I'm disappointed that Shopify does not support javascript function calls to be entered for Links (hrefs) in their editor. Javascript function calls in hrefs are such a normal (and powerful) approach to custom functionality. 

John