Hi, I’m running into a persistent issue with a Wix button.
Every time I add code using $w('#myButton').onClick(() => { ... })
, the button’s default behavior stops working — even if I don’t override anything in the function. For example, even this simple handler breaks the link:
$w.onReady(() => {
$w('#whatsappButton').onClick(() => {
console.log('clicked');
});
});
The button is set (in the editor) to open an external WhatsApp link in a new tab. But once the code runs, the link no longer opens. I’ve tried using wixWindow.openExternalLink()
, window.open()
, and even just letting Wix handle it — but once .onClick()
is present, the navigation is blocked.
Even worse, window
and dataLayer
are undefined in this context, so I can’t send events to Google Tag Manager either.
Is this expected behavior? Or is this a known bug in how buttons behave in Wix when code is attached?
Thanks!