[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/API/HTMLImageElement/decode [Back]  [Original]

HTMLImageElement: decode() - Web API | MDN

MDN Web Docs

View in English Always switch to English

HTMLImageElement: decode()

Baseline

20201

decode() HTMLImageElement DOM (Promise)

DOM DOM DOM DOM

js
decode()

Promise undefined

EncodingError

DOMException

decode() HTMLImageElement URL decode()

decode() DOM

js
const img = new Image();
img.src = "nebula.jpg";
img
  .decode()
  .then(() => {
    document.body.appendChild(img);
  })
  .catch((encodingError) => {
    // 
  });

js
const img = new Image();
img.src = "img/logo.png";
document.body.appendChild(img);

decode() DOM

js
async function getImage() {
  const img = new Image();
  img.src = "img/logo.png";
  await img.decode();
  document.body.appendChild(img);
  const p = document.createElement("p");
  p.textContent = "Image is fully loaded!";
  document.body.appendChild(p);
}

HTML
# dom-img-decode-dev


Web Proxy Viewer  |  New URL  |  Original Page