Created
March 11, 2022 00:34
-
-
Save n1n9-jp/73d04cdc49b88620b417a8d18729adf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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