DEV Community

Sriram
Sriram

Posted on

Interesting behavior of window.location.href

We recently had a small hiccup in downloading multiple files from a portal. We got blocked by browser saying its a popup or request client to allow multiple file download.

What are we trying to do ?

We have to download 3 files once client clicks on "Download all files" button. We don't want client to allow pop-up or allow multiple downloads

What are the options

  1. Use a library to download like filesync or saver

We don't like to use a library just to resolve this problem

  1. Use window.open

But this will be blocked by browser as pop-up.

  1. Use window.location.href

Well, if you use this, you can get it . Yet, if you trigger multiple urls with it, it will "override" the previous URL.

So, how to solve it

  • Use windown.location.href with settimeout

To read more about it, you can see this amazing article from Ryo Mac

https://medium.com/psynamic/demystifying-the-event-loop-featuring-settimeout-f702d4020d9a

This sets a delay in execution and helps with override of url.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay