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?

有帮助吗?

解决方案

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:

http://jsbin.com/xokar/1/edit

You could also use wrap, like onload = "loaded(wrap(this))", but it's best to avoid referring to wrap|unwrap if you can.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top