Button click- open link AND onClick event

Hey.
The problematic situation is this:
I have a button that is connected to a link, to open in a new window, via setting the .link and .target properties of the button.
At the same time, I would like to place some code on the onClick event of that button.
It seems like only one of the options run - if I bind it to the onClick event, the link doesn’t work.
So how can I run code AND open the link in a new window at the same time?
Code:

Inside on onReady for the page:
$w ( ‘#buttonJoinSession’ ). onClick (( event ) => joinSessionClick () );


Inside another function:
$w ( ‘#buttonJoinSession’ ). target = “_blank” ;
$w ( ‘#buttonJoinSession’ ). link = space . link ;
The above link is NOT being opened upon click after setting the onClick event as above.


function joinSessionClick () {
wixWindow . openLightbox ( “Translated Session”);
}

THANKS

Hi there :wave:t2: Share your code and you might get some better help, it’s difficult to assist without seeing your code

For me, it’s working fine. I quickly check it out.

$w.onReady(function () {
    $w('#button1').link = 'https://www.wix.com';
    $w('#button1').target = '_blank';

    $w('#button1').onClick(() => {
        console.log(1);
    })
});

What is your use case?

so for you both the event is executed AND the link is being opened?

@dagsman Yes, my code is work. here is

https://alexanderz5.wixsite.com/redirect-example

With lightbox, it works too.

import wixWindow from 'wix-window';

$w.onReady(function () {
    $w('#button1').link = 'https://www.wix.com';
    $w('#button1').target = '_blank';

    $w('#button1').onClick(() => {
        wixWindow.openLightbox('Announcements (Reopening)');
    });
});

No way. This doesn’t work at all.

:thinking: Oh, so Web Component? :hugs: