Home  >  Article  >  Web Front-end  >  [JavaScript] Detect (judge) whether a link (URL) is valid (service available)

[JavaScript] Detect (judge) whether a link (URL) is valid (service available)

高洛峰
高洛峰Original
2016-11-25 13:39:432472browse

How to use javascript to determine whether the requested url/link is valid (connectable, usable)?

Introduction

There is an address book system deployed on several servers at the same time, but there is a link to the address book on the homepage, link to The problem with this system is that sometimes the server to which the link points fails, so we hope that when this server fails (the service is unavailable), we can point to links to other servers.

Solution 1: XMLHTTP solution

The following code Excerpted from meizz's reply in [2]: