开发者

Check if an URL exists with Javascript with a Firefox extension

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜