nijicp
09-22-2011, 04:38 PM
I need to check the whether an external url like http://www.somesite.com exists or not using javascript.
I have a ajax method for it,
function checkUrl(url) {
var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
alert("URL Exists!");
}
else if (xmlhttp.status==404) {
alert("URL doesn't exist!");
}
else {
alert("Status is "+xmlhttp.status);
}
}
}
xmlhttp.open("HEAD", url ,true);
xmlhttp.send();
}
But is not successful for finding existence of external urls.
Any help...
Thanks in advance..
I have a ajax method for it,
function checkUrl(url) {
var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
alert("URL Exists!");
}
else if (xmlhttp.status==404) {
alert("URL doesn't exist!");
}
else {
alert("Status is "+xmlhttp.status);
}
}
}
xmlhttp.open("HEAD", url ,true);
xmlhttp.send();
}
But is not successful for finding existence of external urls.
Any help...
Thanks in advance..