Images created using `document.currentScript.ownerDocument.createElement` (from within <link> imported HTML) never load

前端 未结 1 1894
天命终不由人
天命终不由人 2020-12-21 19:09

Here\'s a function that returns the width of an image, given the image\'s url:

async function getImageWidthByUrl(imgUrl) {
  const imgEl = document.createEle         


        
1条回答
  •  孤城傲影
    2020-12-21 19:28

    It's the normal behaviour.

    The image referenced in the src attribute element in an imported document with is not loaded until it is appended to the main document.

    From the HTML Imports tutorial:

    Think of content as inert until you call upon its services. [...]

    Unless you append it's content to the DOM, it's a no-op. In fact, the only thing that "executes" in the import document directly is

提交回复
热议问题