Opening external link when clicking on a table

Hello!

When a user clicks anywhere on the table, I would like them to be directed to an external link. I’ve tried to learn the handlers but not even sure if I’m on the correct trajectory. Here’s what I have thus far (used wix.com for placeholder):

Use location and I believe the external pages will open in new window by default.

Hey Josh,

Couple of things to add to Andreas’ answer.

  • If you use the Properties panel to add the click event, your code should look like this:
export function table1_onClick(event) {
    wixLocation.to("http://externalSite.com");
}
  • If you want to code it yourself and create a dynamically bound event handler the code should be inside the onReady function like this:
$w.onReady(function () {
    $w("#table1").onClick((event) => { 
        wixLocation.to("http://externalSite.com"); 
    });
});
  • In either case you don’t need the “let”.
  • Don’t forget to add this to the top of your code before the onReady:
import wixLocation from 'wix-location'; 

BTW- I noticed that adding the click event to the table doesn’t change the pointer to a pointing hand in the published site. Meaning your site visitors won’t have an indication that the table is click-able. I’ve already reported this as a bug.