OnClick event and linking a button not possible? (solved)

I’ve made a drop down menu, it almost works, but when someone choose a product category from the dropdown menu, i want it to link to an product category page and then close the strip i use as the dropdown menu…

i wanted to make an OnClick event that closes the strip and linking the button to a page? - But the button does not work, when i’ve made an OnClick event… Any ideas or suggestions?

I’ve added an image to show the dropdown menu i have made

Hi Mattias,

Having both link and onClick is not a good practice, as you define two different behaviours for a button.
As a solution, at the end of your onClick function, use wixLocation.to .


1 Like

Awesome i’ll try that, thanks Liran

Hi Liran,
The wixLocation.to is not working for me…

view my post here:

Hi mattias,
Can you please share a link to your site so we can inspect ?

Sorry for the delay, i had to finish the webiste before publishing, because its a business webiste :smiley: The link is below:

Just hover over the menu and choose “produkter” here you will find it.

Hi Mattias,

is this still an issue? It seems to work very well.

No it works great it was just because i was using the page name instead of the seo url name… Stupid mistake, but it works now :smiley:

Hello, Im trying the same thing but a bit complicated and I can’t make that link to work. I’m trying to create a button (with an icon that is a custom image) that after clicking:

  1. leads to another page of my website
  2. hides itself revealing what is underneath

The problem I have so far is that whenever I apply onClick to any icon the link just doesn’t work on click even if its there. I tried to link the page via the button editor and also via onClick code and there is no way i can make the icon to lead anywhere. It works as soon as I take out the onClick thingy.

Thank you so much

Try this:

import wixLocation from “wix-location”;

export function moninactive_click(event, $w) {

If its on your site, it should work with the link :slight_smile:

1 Like

Thanks a lot Mattias, that worked!!

1 Like

You’re welcome, im glad it helped :slight_smile:

Hi Mattias,

I’m facing a similar issue.
I’m trying to attach a trackevent to a button click. It seems to work fine when the link on the button is to an external page e.g. Google. But when the link is to another page on my own website , the link does not work, although the event does get triggered.

I tried your suggetion of WIxLocation.to (“/page”) given above, but am getting an "Unexpected token " error message - it seems to have a problem with the period between wix and location.

Could you help, please?


BTW - What IS an Unexpected token error, and how can it be fixed?
Sorry for the naive question - I am not a coder :0)

Hi Kumarnareshk333,

i’m also kinda new to coding, so no problem :wink:

Actually, i can’t se what the problem should be, can you maybe take a screen shot of your code? :slight_smile:

An unexpected token, comes from a minor mistake forexample, you forgot the " } " in the en of the code, then there will come an unexpected token… So maybe just an missing symbol, or something, but send me a screenshot, then i can see if i can figure out where the problem is :slight_smile:

Hi Liran and Roi,
I agree on " define two different behaviors for a button " is not good.
But in the case on GA event it is necessary.
In addition it contradicts this:

Therefore it is a bug, and using wixLocation is a workaround to live with the bug.


Has this been solved… running into the same thing right now – it essentially broke my site and didn’t realize.