Yes it worked. thank you.
Topic summary
A user seeks to make the first banner image in Shopifyâs Dawn 15.0 theme clickable. Two developers provide competing solutions involving modifications to the image-banner.liquid file.
Solution 1 (Shadab_dev):
- Adds JavaScript code using
document.querySelectorand an event listener - Creates a custom link field in the theme customizer
- Initially causes a 404 error when clicking the banner
- Later corrected by changing
e.targettoe.currentTargetin the JavaScript
Solution 2 (namphan):
- Modifies CSS to add a clickable overlay layer
- Uses Shopifyâs built-in URL picker in the customizer
- Avoids JavaScript-related errors
- Points out two issues with the JS approach: problems with multiple sections and incorrect URL rendering
Resolution:
The original poster confirms namphanâs solution works successfully. Another user later validates this approach. The discussion highlights the importance of proper URL handling in Shopify themes and the potential pitfalls of using JavaScript event targeting with dynamic content.
Hi @Steph1232aqwse ,
You just need to follow this guide, then add the link at Customize, it will work fine, no need to change any code according to anyone elseâs instructions.
If you have any questions, you can contact me directly.
Happy to help you ![]()
@Steph1232aqwse I was facing this issue but i realised it was only happening when I linked to a page or product or any where within my store that was not correctly set up. Please make sure the page or link you are redirecting is set up properly. If it still persists let me know I will take a look at it again.
Thanks
Hi @Shadab_dev , @Steph1232aqwse
It has 2 errors that will happen if you use this JS code for this:
-
You use âdocument.querySelectorâ so when you use 2 sections it will cause error in 2nd section.
-
Because you use Shopify âurlâ, so when selecting a product, the link will be rendered as â/products/handle productâ, so you use 'window.location.href =
${target}â it will cause page 404.
Hope itâs clear ![]()
@Steph1232aqwse I get the mistake i was making. My Solution remains the same. Only change the code on the file that is down below after everything to this
Rest of the code is same. Man if this does not work i am not replying to this thread ever.
@namphan I see my mistake. i just had to use currentTarget instead of target so that even if someone clicks inside the banner to different element it will look for the banner since i have the click listener on the banner.
Hope you get the point.
Thanks
just followed your instructions and it was perfect!!! Thank you!!!
Great it worked out for you. The repetition in exclamation marks tells that you really wanted this. Glad I could be of help.
Good luck on your store and your business.
Best Regards
Shadab
Hi @CuttingEdgeProm ,
Youâre welcome and happy to help you