Home > Web Front-end > JS Tutorial > body text

JavaScript implementation method to determine whether a URL link is valid_javascript skills

WBOY
Release: 2016-05-16 18:01:13
Original
1592 people have browsed it

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, linked to this system. The problem is that sometimes the server pointed to by the link fails, so I hope that on this server In case of failure (service unavailable), links to other servers can be pointed to.
Solution 1: XMLHTTP solution
The following code is excerpted from meizz's reply in [2]:

Copy code The code is as follows:


csdn

Disadvantages: Use ActiveXObject, so it is IE Only. Non-IE core browsers are not available.
Solution 2: jQuery extension
For the following content, please refer to [1]
Home page: http:/ /plugins.jquery.com/project/linkchecker
Demo page: http://sidashin.ru/linkchecker/
The downloaded compressed package contains calling examples.
Supplement:
If you target a The specific URL, just using jQuery without a plug-in, can be like this:
Copy the code The code is as follows:

$.ajax({
url: 'http://some.url.com',
type: 'GET',
complete: function(response) {
if(response. status == 200) {
alert('valid');
} else {
alert('invalid');
}
}
});

Reference documents:
[1]http://zhidao.baidu.com/question/138740329.html?push=ql

[2]http://topic.csdn. net/t/20041214/16/3644539.html
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template