Using corvid to open a link when button is clicked

I’m trying to set up a button to open a link in another tab, but I want to use Corvid, rather than the editor GUI.

I’ve set it up as follows, according to the Corvid APi support documentation, but it doesn’t work. Please advise me on what I have done wrong.

Thanks,
Liam

1 Like

You need to put the following lines of code into the page’s onReady() function, like this:

$w.onReady(function () {
    $w("#button1").link = "http://wix.com";
    $w("#button1").target = "_blank";
});

Make sure that the button is not bound to a button_click() event handler:

Thanks so much for the speedy reply. I did that and it worked perfectly, however I was already using the onClick event handler to trigger a fade effect (I want the buttons to reveal an element underneath when clicked).

Is there another way to trigger the fade effect on click? Or in other words; combine the two events (
screenshot 1 and screenshot 2 respectively)?

export function button_click(event) {
let fadeOptions = {
“duration”:500,
“delay”:1000
};

$w(“#group48”).hide(“fade”, fadeOptions);
}


$w.onReady(function () {
$w(“#button39”).link = “http://wix.com”;
$w(“#button39”).target = “_blank”;

});

Instead of setting the .link property of the button, you could use wix-location.to() in the button_click() function. Something like this (not tested):

export function button_click(event) {
    let fadeOptions = {
        "duration":500,
        "delay":1000
    };

    $w("#group48").hide("fade", fadeOptions)
    .then( ( ) => {
        console.log("Done with fade");
        wix-location.to("http://www.wix.com");
    }
} );

Thanks for all your help. I edited it a bit and that worked in thew current tab, but it seems there’s no way to use wix-location to open a link in a new tab.

I don’t want to waste your time cos I’m quite new to this. But essentially is there no way to have a button open a link in a new tab, and execute another event on the button in the original tab (in my case hide)?

Thanks,
Liam