Skip to content

Instantly share code, notes, and snippets.

@macloo
Created November 24, 2020 16:28
Show Gist options
  • Save macloo/f9c2570efc39c98ab3dd6fb4687ab743 to your computer and use it in GitHub Desktop.
Save macloo/f9c2570efc39c98ab3dd6fb4687ab743 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Detect 404 </title>
</head>
<body>
<p>Hello.</p>
<script src="detect_404.js"></script>
</body>
</html>
// check if one URL is good or not
function urlExists(url, callback) {
fetch(url, { method: 'head' })
.then(function(status) {
callback(status.ok)
});
}
// URLs in an array
// bad - BlZ57nzj6xZ
// good - BlafBtHniQQ
const url_list = [
'https://www.instagram.com/p/BlZ57nzj6xZ/',
'https://www.instagram.com/p/BlafBtHniQQ/'
];
// loop over all URLs in list
for (let i = 0; i < url_list.length; i++ ) {
url = url_list[i];
urlExists(url, function(exists) {
if (exists) {
// it exists, do something
console.log("It is good.");
} else {
// it doesn't exist, do something else
console.log("It is bad.");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment