Skip to content

Instantly share code, notes, and snippets.

@n1n9-jp
Created March 11, 2022 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n1n9-jp/73d04cdc49b88620b417a8d18729adf5 to your computer and use it in GitHub Desktop.
Save n1n9-jp/73d04cdc49b88620b417a8d18729adf5 to your computer and use it in GitHub Desktop.
// https://www.finleyghosh.com/blog/check-for-a-page-404-with-only-javascript
function UrlExists(url) {
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
if (http.status != 404)
return true;
else
return false;
}
if ( UrlExists(selectedTextPath) ) {
// load external file.
} else {
// don't load.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment