1function checkImage(url) {
2 var request = new XMLHttpRequest();
3 request.open("GET", url, true);
4 request.send();
5 request.onload = function() {
6 status = request.status;
7 if (request.status == 200) //if(statusText == OK)
8 {
9 console.log("image exists");
10 } else {
11 console.log("image doesn't exist");
12 }
13 }
14}
15checkImage("https://picsum.photos/200/300");
1// create an XHR object
2const xhr = new XMLHttpRequest();
3
4// listen for `onload` event
5xhr.onload = () => {
6 if (xhr.status == 200) {
7 console.log('Image exists.');
8 } else {
9 console.log('Image does not exist.');
10 }
11};
12
13// create a `HEAD` request
14xhr.open('HEAD', '/img/bulb.svg');
15
16// send request
17xhr.send();
18
1function checkImage(url) {
2 var request = new XMLHttpRequest();
3 request.open("GET", url, true);
4 request.send();
5 request.onload = function() {
6 status = request.status;
7 if (request.status == 200) //if(statusText == OK)
8 {
9 console.log("image exists");
10 } else {
11 console.log("image doesn't exist");
12 }
13 }
14}
15checkImage("https://apitest.cargoxrate.com/cache/upload/39908016179913740685.jpg?https://picsum.photos/200/300");