header, side menu and footer on all pages

Asked

Viewed 25 times

1

How to use the same footer, side menu and header on all pages of my site? For header and footer, I tried the following:

<html>

<head>
    <script src="jquery-3.3.1.min.js"></script>
    <script>
        $(function() {
            $("#header").load("header.html");
            $("#footer").load("footer.html");
        });
     </script>
</head>

<body>
    <div id="header"></div>

    <h1>conteúdo</h1>

    <div id="footer"></div>
</body>

</html>

but it won’t; only the content appears. The header/footer.html and jquery files are in the same folder, all with correct names and extensions. What am I doing wrong?

  • You are doing this on server or local machine?

  • @Leocaracciolo It is that the method does not work in Chrome via FILE protocol. In Firefox, for example, it works.

  • really, I tried it here on Mozilla and it worked. Thanks!!! , but how to make it work on Chrome too?

  • @dvd, tonces is local

  • The problem is that . load() for local files is blocked by Chrome for security reasons. It appears that there is a solution in https://stackoverflow.com/questions/245926/jquery-load-method-not-working-in-chrome

  • http://www.chrome-allow-file-access-from-file.com/

Show 1 more comment
No answers

Browser other questions tagged

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