We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We've not had way to import html until now. But from now, we can import html documents using html import.
html import
can i use : http://caniuse.com/#feat=imports
At the moment (2014/11/01) we can it only Google Chrome, Opera, and Chrome for Android
Google Chrome
Opera
Chrome for Android
You can import HTML using <link rel="import">
<link rel="import">
main HTML
<head> <link rel="import" href="/path/to/imports/stuff.html"> </head>
You have to append elements you import if you want to use it.
Imported HTML (stuff.html)
<nav> <ul> <li>page 1</li> <li>page 2</li> <li>page 3</li> </ul> </nav> <script> var importDoc = document.currentScript.ownerDocument; // imported HTML var mainDoc = document; // main HTML var nav = importDoc.querySelector('nav'); mainDoc.querySelector('.navi-outer').appendChild(nav.cloneNode(true)); </script>
You can also use imported elements from main HTML like that.
var link = document.querySelector('link[rel="import"]'); var nav = link.import.querySelector('nav'); document.querySelector('.navi-outer').appendChild(nav.cloneNode(true));
Imported HTML
<link rel="stylesheet" href="/path/to/imports/stuff.css">
You have to append link tag if you want to apply that style.
link tag
<link rel="stylesheet" href="/path/to/imports/stuff.css"> <script> var importDoc = document.currentScript.ownerDocument; // imported HTML var mainDoc = document; // main HTML var style = importDoc.querySelector('link[rel="stylesheet"]'); mainDoc.head.appendChild(style.cloneNode(true)); </script>
You can use those contexts in imported document.
document.currentScript.ownerDocument
document
css
html
The text was updated successfully, but these errors were encountered:
No branches or pull requests
date: 2014-11-01
title: Getting Start HTML Import
slug: start-html-import
lang: en-US
tags: [webcomponent]
Outline
We've not had way to import html until now.
But from now, we can import html documents using
html import
.Capability
can i use : http://caniuse.com/#feat=imports
At the moment (2014/11/01) we can it only
Google Chrome
,Opera
, andChrome for Android
Usage
Import HTML from main HTML
You can import HTML using
<link rel="import">
main HTML
You have to append elements you import if you want to use it.
Imported HTML (stuff.html)
You can also use imported elements from main HTML like that.
main HTML
Import CSS in imported HTML
Imported HTML
You have to append
link tag
if you want to apply that style.Imported HTML (stuff.html)
Javascript context in imported HTML
You can use those contexts in imported document.
document.currentScript.ownerDocument
.document
Notice
css
andhtml
tag after import html.References
The text was updated successfully, but these errors were encountered: