Tagged: menu links, onclick event
`Hi there!
Is it possible to add onclick event on menu links at header? The event is to link url or internal page. What I wanted to achieve is to change the HREF with an onclick event. for HTML here’s what I did.
<a href="javascript:void(0);" onclick="window.location.href='https://example.com'">onclick link!</a>
onclick link!
Hey Rommel,
Why do you need to use JavaScript if it is a normal link behavior to follow to the url provided and the link can be styled as a button if needed?
Best regards,
Victoria
Hi,
Thank you for the update.
It’s not possible to add an onclick attribute by default but you can listen for a menu item click event.
// https://api.jquery.com/on/
// https://www.w3schools.com/jquery/event_on.asp
Best regards,
Ismael
Hello,
We are actually trying to deny crawlers from seeing some of the menu links. We want to avoid using nofollow. So making some link in the menu as javascript or something google bots cannot read is our only option. Would you have a suggestion?
Thanks,
Rommel
Hi Rommel,
Well, you need to use empty links for the menu and use some JavaScript to handle clicks on those items, but this is the customization that we do not provide within the scope of the support here, unfortunately.
You might want to hire someone to do it for you.
Best regards,
Victoria