In the HTML Import polyfill, how do you get the imported content?
-
20-12-2019 - |
Question
Under native HTML Imports, a <link rel="import" href="...">
will, once loaded, have an .import
property pointing to the imported document. Under the polyfill, this property does not seem to be available. (See http://jsbin.com/sifem/4/edit, which displays "Got content" in the console under native HTML Imports in Canary, and "No content" under the polyfill.)
How then can one reliably access imported content in code?
Solution
When you wrote onload="loaded(this)"
you bypassed the ShadowDOMPolyfill, so the reference received in loaded
is unwrapped and unsuitable for use.
addEventListener
doesn't have this problem:
You could also use wrap
, like onload = "loaded(wrap(this))"
, but it's best to avoid referring to wrap|unwrap
if you can.