fetch("awesome-picture.jpg")
.then((response) => {
const elem = document.getElementById("warning-message-box");
elem.textContent = response.redirected ? "Unexpected redirect" : "";
// final url obtained after redirects
console.log(response.url);
return response.blob();
})
.then((imageBlob) => {
const imgObjectURL = URL.createObjectURL(imageBlob);
document.getElementById("img-element-id").src = imgObjectURL;
});Response: redirected property / notebook
Response: redirected property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
fetch("awesome-picture.jpg", { redirect: "error" })
.then((response) => response.blob())
.then((imageBlob) => {
const imgObjectURL = URL.createObjectURL(imageBlob);
document.getElementById("img-element-id").src = imgObjectURL;
});