How to split html text file into multiple files?

Very simple html question.

Since it is <body>too long, I want to split the file into several files. This is not about using iframes, etc., but just need to include some text files to create an <body>html file.

Thanks!

+5
source share
4 answers

You can do it with jquery

<head> 
  <script src="jquery.js"></script> 
  <script> 
    $(function(){
      $("#Contenttoinclude").load("b.txt or b.html"); 
    });
  </script> 
</head> 

and load it in html

<body> 
 <div id="Contenttoinclude"></div>
</body>
+6
source

Just change the extension to .phpinstead .html. Then you can simply put, for example, your whole head into a file head.php(or head.inc).

All this would look like this:

<!DOCTYPE html>

<?php
  include 'head.php';
?>

<body>
 <!-- stuff in here -->
</body>

<html>

You can divide your body into separate parts as follows:

<body>

<?php
  include 'firstPart.php';
?>

<!-- some other stuff -->

</body>
+1

You can easily split your code into multiple files, then create one file with the .php extension and include them all!

0
source
<body>
    <span id="navbar"></span>
    <span id="content"></span>
    <span id="footer"></span>

    <script src="/path/to/js/fileA"></script>
    <script src="/path/to/js/fileB"></script>
    <script src="/path/to/js/fileC"></script>

    <script>
        // In actuality this is a different file...
        document.getElementById('content').innerHTML = (
            '<div class="row">
                    <div class="row">1</div>
                    <div class="row">2</div>
                    <div class="row">3</div>
                </div>'
        );
    </script>
</body>
0
source

Source: https://habr.com/ru/post/1619609/


All Articles