HTML – Uvoz sadržaja iz druge datoteke

Zadatak

Tvoj zadatak, odlučiš li prihvatiti ga, jest koristiti HTML i negdje u tekstu stranice “index.html” umetnuti sadržaj datoteke “stranica_dva.html“.

index.html

<!doctype html>
<html lang="hr">
<!-- HEADER -->
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="šđčćž ŠĐČĆŽ" content="šđčćž ŠĐČĆŽ">
<title>šđčćž ŠĐČĆŽ</title>

<script>
function fnUcitajStranicu() {
  var z, brojac, elmnt, file, xhttp;
  z = document.getElementsByTagName("*");
  for (brojac = 0; brojac < z.length; brojac++) {
    elmnt = z[brojac];
    file = elmnt.getAttribute("ucitajStranicu");
    if (file) {
      xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4) {
        elmnt.innerHTML = this.responseText;
        elmnt.removeAttribute("ucitajStranicu");
        fnUcitajStranicu();
        }
      }
    xhttp.open("GET", file, true);
    xhttp.send();
    return;
    }
  }
};
</script>

<!-- BODY -->
<body>

<!-- Ovdje sada umećemo sadržaj vanjske datoteke -->
<H1>Import</H1>
Import datoteke "stranica_dva.txt":<br>
<div ucitajStranicu="stranica_dva.txt"></div>

<!-- FOOTER -->
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script>fnUcitajStranicu();</script>

</body>
</html>

stranica_dva.html

STRANICA2: šđč枊ĐČĆŽ

Rezultat


html xhtml import ximport uvoz xuvoz 3rd x3rd include xinclude insert xinsert umetni xumetni umetanje xumetanje vanjski xvanjski stranica xstranica

image_pdfimage_print