JSFiddle - React, Tailwind, and code Playground
by YinCognito
JavaScript
var sampleurl = "https://upload.wikimedia.org/wikipedia/commons/4/4c/%27Matijevic_Hill%27_Panorama_for_Rover%27s_Ninth_Anniversary_%28False_Color%29.jpg",
contenttype = "";
function xhrresponseheader(surl)
{
var xhr = new XMLHttpRequest();
xhr.open("HEAD", surl);
//xhr.withCredentials = false;
xhr.onreadystatechange = function()
{
if (xhr.readyState === 4)
{
contenttype = xhr.getResponseHeader("Content-Type");
console.log("Content Type (XHR): ", contenttype);
}
}
xhr.send();
}
function fetchresponseheader(surl)
{
fetch(surl).then
(
function(response)
{
contenttype = response.headers.get("content-type");
console.log("Content Type (FETCH): ", contenttype);
}
);
}
xhrresponseheader(sampleurl);
fetchresponseheader(sampleurl);