Check if URL Exists
Question from Instagram
by kuonyuu
HTML
<h1>By <a href="//google.com/+ShahDanial" target="_blank">Shah Danial</a></h1>
JavaScript
var MrChecker = new XMLHttpRequest(),
CheckThisUrl = "https://ncode.syosetu.com/n7175jr/1/";
// Opens the file and specifies the method (get)
// Asynchronous is true
MrChecker.open('get', CheckThisUrl, true);
//check each time the ready state changes
//to see if the object is ready
MrChecker.onreadystatechange = checkReadyState;
function checkReadyState() {
if (MrChecker.readyState === 4) {
//check to see whether request for the file failed or succeeded
if ((MrChecker.status == 200) || (MrChecker.status == 0)) {
alert(CheckThisUrl + ' page is exixts');
}
else {
alert(CheckThisUrl + ' not exists');
return;
}
}
}
MrChecker.send(null);