开发者

Check if an URL exists with Javascript with a Firefox extension

开发者 https://www.devze.com 2023-03-11 00:53 出处:网络
I\'开发者_StackOverflow中文版d like to check if a given URL exists using Javascript with a Firefox extension.I guess you want to try loading the URL - use XMLHttpRequest for that:

I'开发者_StackOverflow中文版d like to check if a given URL exists using Javascript with a Firefox extension.


I guess you want to try loading the URL - use XMLHttpRequest for that:

var request = new XMLHttpRequest();
request.open("GET", url);
request.onload = function()
{
    if ((request.status >= 200 && request.status < 300) || request.status == 304)
        alert("Exists!");
    else
        alert("HTTP response isn't success, URL doesn't exist or is currently unavailable");
};
request.onerror = function()
{
    alert("Loading URL errored out, server doesn't exist or is currently unavailable");
};
request.send(null);
0

精彩评论

暂无评论...
验证码 换一张
取 消