Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

  • This WPT test may be referenced by the following Test IDs:
    • /html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-adopt-lazy-iframe-from-script-disabled-document.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<title>Test lazy loading iframe remains lazy loading originally created
in a script-disabled document, then got adopted to a regular document</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<script>
const t = async_test("Test lazy loading iframe remains lazy loading originally created" +
"in a script-disabled document, then got adopted to a regular document");
const lazyIFrameInScriptDisabledDocumentOnLoad =
t.unreached_func("lazy loading iframe shoudn't be loaded because it's not visible");
window.addEventListener("load", t.step_func(() => {
const parser = new DOMParser();
const remoteDoc = `
<!DOCTYPE html>
<html>
<iframe
id="lazyIFrameInScriptDisabledDocument"
src="resources/subframe.html"
loading="lazy"
width="600"
height="400"
style="display: none"
>
Your browser does not support iframes.
</iframe>
</html>`;
const htmlDoc = parser.parseFromString(remoteDoc, "text/html");
var newIframe = htmlDoc.getElementById("lazyIFrameInScriptDisabledDocument");
newIframe.onload = lazyIFrameInScriptDisabledDocumentOnLoad;
document.body.appendChild(newIframe);
// Give some time to the "load" event to fire.
t.step_timeout(t.step_func_done(), 2000);
}));
</script>
</html>