0

I want to put a link with the <a> tag on my website page, but with multiple URLs in case the 1st one doesn't work. I would be something like this:

<a href="url1;url2;url3"

But of course this doesn't work. So is there a way to do this ?

Thank you

mric750
  • 183
  • 8

3 Answers3

0

What do you mean by "1st one doesn't work" ? That the server is sending an error ? It's not possible to do what you want just with HTML.

It could be done by Javascript by adding a listener to the anchor, sending HTTP request on the first url to see if you receive 200 or an error like 500. In case of an error, you check the second url and so on and redirect the user where you received a 200.

Otherwise, if you just want to open all the links, there was already a post about that here: How can I open multiple links using a single anchor tag

Community
  • 1
  • 1
Hyukchan Kwon
  • 382
  • 1
  • 5
  • 20
0

The closest you could come would be to:

  1. Put a default URL in the href
  2. List alternative URLs elsewhere (such as in a data attribute)
  3. Bind a click event handler that runs some JavaScript which prevents the default behaviour and then tests each URL in turn until it finds one that works (or runs out).

Testing would require Ajax which would require either:

  • Permission via CORS from each URL you test
  • The user of a proxy (which would test availability of the URL to your proxy and not to the browser)

The additional HTTP requests would consume bandwidth (and thus time).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

There's no way of doing this with pure HTML since HTML can't detect whether or not what you mean by "doesn't work" applies to a given URL.