Header and Footer on all pages (static site)

Asked

Viewed 235 times

-1

I want to leave just one page for the header and the footer, since they are the same. However the same code I used some time ago is not working and I did not find a reason for this.

Obs: I tried using jQuery, following the logic below:

  <script>
     $(function () {
        $("#header").load("header.html");
        $("#footer").load("footer.html");
     });
  </script> 
  • In addition to my reply, you can also use the Html5 import that is already supported by all relevant browsers, only in some mobile browsers that still do not have full compatibility, as is the case with Safari, no new so far. Apple and Microsoft are very corporatist, take a while, resist at all costs if not developed by them, but in the end they implement.

2 answers

0

And it has to be you? you don’t say exactly why, but alternatively, you can do it with php and decent hosting or not at all, should offer you a server with php support, just create a file with extension '.php' and open the tag '<?php codigo aqui ?>'. ai you can use include to lynch the file. Follow: https://www.php.net/manual/en/function.include.php to learn more. Remembering that the mere use of php will not make your site dynamic, so rest assured. Use this so no one will see what you are doing, because php will embed in the main code:

<html>
<head></head>
<body>
<?php include 'main.php'; ?>

<!--- content code --->

<?php include 'footer.php'; ?>
</body>
</html>

Ready, then you create in the same folder where is the main file (that is calling the other files) the following files:

  • main.php
  • footer.php

Inside them, put your html, it’s just that! a php file doesn’t necessarily have php, but if you need it, you already know that it accepts.

  • When using html, don’t put html inside the php tag, for example: <?php <div></div> ?>. Put out the php tag just like you would in an html file, the usage is the same and of course, you can use html inside the php tag no more directly, there is a method specific to it.

0

BS: personal, thanks for all the answers, at the end of the accounts it was a question of folder permission, which for some reason was preventing the loading of the contents, but now it can solve. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.