8
Recently I came across the current TAG documentation <link>
on the website W3.org - http://www.w3.org/TR/html-imports where you specify that you can import content with mime-type text/html, ie HTML files. This would solve a current problem that I have to factor the contents of my application into several HTML files.
I made a small example that worked only on Chromium (the Google Steroid Browser).
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Seres Humanos</title>
<link id="heart-html" rel="import" href="heart.html">
</head>
<body>
<p>O que um homem sem um coração ?</p>
<script>
var link = document.querySelector('link#heart-html');
var heart = link.import;
// Acesso o DOM do documento em heart.html
var myHeartMsg = heart.querySelector('p#text');
console.log(myHeartMsg.innerHTML);
</script>
</body>
</html>
Heart.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>heart</title>
</head>
<body>
<p id="text">Este é meu coração</p>
</body>
</html>
I searched extensively on the web and could not find information about what would be the support forecast for this Feature, i.e., importing text/html content into modern browsers using the link tag ?
The HTML5 Rocks has an amazing posting (in English) on the subject... too bad there is compatibility yet in browsers.
– Miguel Angelo
Another interesting article on the subject: http://robdodson.me/blog/2013/08/20/exploring-html-imports/
– bfavaretto
Thank you @bfavaretto for sharing this link. I will look fondly.
– João Paraná
Thank you @miguel-Angelo for sharing this link. I’ll look kindly
– João Paraná