combined with this on the URLs I want to trigger it:
`javascript:delay('URL goes here')
and this works perfectly… however the site is getting built out more and integrating the CMS. I actually don’t have any links that shouldn’t trigger this, so I tried using this global jquery version for delaying all links:
$(function(){
$("a").click(function(evt){
var link = $(this).attr("href");
setTimeout(function() {
window.location.href = link;
}, 500);
});
});
Unfortunately this breaks all Webflow interactions.
Does anyone know another way to globally add a delay to all links? Failing that, is there some way that I can integrate it with the CMS, since ideally I want to be able to use the ‘links to: current page’ feature, otherwise it looks like I’ll need a separate CMS collection list for every link in a collection, so that the js trigger can be manually inserted as the URL…
I can make this all work with workarounds I just thought maybe someone has previously found a solution. It’s further compounded by not being able to use the JS within collection pages so looks like absolutely every link is going to have to be managed manually and no CMS page templates… or ditch the transitions.
@joshuafry I’m sure it’s possible but without seeing the live site it is very difficult to troubleshoot. You could clone the project and remove any of the branding to avoid violating the NDA, but beyond that I’m not sure I can help.
Thank you - OK I think I will probably do that unless I think of something else, I just need to find the time as debranding it is quite difficult. Would really appreciate any help once I get around to it, hopefully later this week.
I updated the code so it doesn’t break the behavior of webflow tabs:
$(function() {
$("a").click(function(evt) {
const targetLink = $(this).attr("href");
if (
$(this).hasClass("w-tab-link") ||
targetLink == "#" ||
targetLink.indexOf("/") == -1 ||
targetLink.indexOf("http") != -1 ||
trimAnchorLink(targetLink) === window.location.pathname
)
return;
evt.preventDefault();
var opensInNewTab = $(this).attr("target");
var itsMail = targetLink.includes("mailto:");
setTimeout(function() {
if (opensInNewTab || itsMail) {
window.open(targetLink, "_blank");
return;
} else {
window.location.href = targetLink;
}
}, 500);
});
});
function trimAnchorLink(link) {
var index = link.indexOf("#");
if (index != -1) return link.substring(0, index);
return false;
}
Keep using this until something else needs to be taken care of. I developed what Tom needed, now if you need something else covered, just post it here and I’ll update the code.
EDIT 1: Disabling delay for in-page links
EDIT 2: Disabling delay for external links
Hi @jeandoc! Thanks so much for your help on this. I tried implementing in my own project, but for some reason it’s not working. I was wondering if you have any idea why? Here’s the read only link.