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);
精彩评论