x-tag / core

The Heart of X-Tag
http://x-tag.github.io/
Other
1.25k stars 151 forks source link

Import document scope, unaccessible or unclear #123

Closed seanupton closed 8 years ago

seanupton commented 9 years ago

I have a template and a script in a document that is imported by <link rel="import"> but the script cannot access the DOM of the imported document. window.document refers to the importing document, of course, and window.document._currentScript.ownerDocument === window.document for me (in Firefox 43.0a2)..

I have, AFAICT, no way to traverse to my template inside the DOM of the imported document Either this is inconsistent with documentation on webcomponents.org about polyfills, or some alternative is underdocumented?

csuwildcat commented 9 years ago

Just to level-set, X-Tag does not use or include the HTML Imports polyfill, so Imports will not work without inclusion of it. We didn't see a ton of benefit to coupling to that spec, given X-Tag developed elements have no reliance on it.

As for the generic question about HTML Imports and dealing with accessing imported documents, you should be able to get the document from the import property on the link element itself, once it loads:

document.querySelector('link[rel="import"]').import

Note: the link element must be in the DOM and the document resource at the other end must be CORS enabled.

csuwildcat commented 8 years ago

Any feedback? I'd like to close this out if this solves your issue.