I recently came across a problem where I needed to replace a Webflow tab link with a custom link/button, but Webflow doesn’t allow links/buttons to be placed inside of tab links. The recommended solution is to rebuild the entire tabs UI using custom interactions, but that would have been a total pain.
After some tinkering in ChatGPT, I created a simple solution that involves replacing the original tab link with a custom link/button using JavaScript.
Here’s the tutorial:
And here’s the scripts:
<!-- 💙 MEMBERSCRIPT #92 v0.1 💙 TURN ANYTHING INTO A LINK -->
<script>
document.addEventListener('click', function(event) {
let target = event.target;
// Traverse up the DOM tree to find an element with the ms-code-navigate attribute
while (target && !target.getAttribute('ms-code-navigate')) {
target = target.parentElement;
}
// If we found an element with the ms-code-navigate attribute
if (target) {
const navigateUrl = target.getAttribute('ms-code-navigate');
if (navigateUrl) {
event.preventDefault();
// Always open in a new tab
window.open(navigateUrl, '_blank');
}
}
});
</script>
I asked good ol’ ChatGPT. To open in the same tab instead of a new one, you need to modify the window.open function in the script. Currently, it’s set to open links in a new tab (_blank ). Change '_blank' to '_self' to open links in the same tab.
Hey @DuncanHamra!!
I’m working on a tab solution for a new project - and I’ve been following some of your amazing tutorials (both the Activate tab on hover instead of click and now this Add link inside tab solution), and you’re an absolute legend for providing these quick tutorials!
My current challenge right now is that I’m trying to create a CMS solution using these techniques – and it’s now really working out for me.
So glad it’s been helpful!! I’m not too familiar with Finsweet’s CMS tab solution So I’m really not sure how to combine them. Are you getting any errors?
Here comes the real challenge!
Hello @DuncanHamra, thank you so much for the priceless help you are providing
I used both MEMBERSCRIPT #79 and MEMBERSCRIPT #92 in the same tab, I am trying to show elements of the tab on hover, while also having the Tab as a link, do you think I can achieve that? (Also the first tab seems to glitch sometimes lol?)
here’s the read-only link Webflow - Villa Romana