Display a loading spinner when clicking a linked button

Hello guys, as said in the title i want my site to display a loading spinner when users click some buttons linked to a dynamic page, this is to provide visual feedback that indeed something is happening because there’s an awkward but short delay in the loading process.

Problem is that whenever i add the onClick() that displays the spinner (html custom element), the link stops working altogether. If you guys can help me achieve my goal that would be great, and if you have a better solution i’ll be glad to read through it.

Just in case you are wondering about the loading time, it’s 2 or 3 seconds long even though it’s an extremely small proof of concept site: 2 small static pages and 2 dynamic pages linked to a 6 entries long dataset. Thanks for everything in advance.

1 Like

The onClick() overrides the button’s link which is why the link stops working.

In any case, it makes more sense to first redirect to the dynamic page (via the button’s link), and then have a spinner on the dynamic page.

@yisrael-wix indeed but this awkward delay happens before the redirection to the dynamic page, when the button is clicked absolutely nothing happens during these 3 seconds I mention, then the page appears and everything is already loaded so I don’t think a spinner would be useful by then.

Aha. But, what are you doing that causes the delay? Any code? If so then please share.

Sounds like what you need to do is to not use the Button’s link setting. Just set up an onClick() that will display a spinner, and then redirect to the dynamic page using wixLocation.to() .