Master page in HTML

Asked

Viewed 1,325 times

1

Good morning! I’m trying to make a Master Page in HTML 5. I created an HTML page called master.html with every menu structure I want. I call this page the following way on my index.php page and it works:

<html>
    <body>        
        <div id="new-header">
            <script>
                $("#new-header").load("page/master.html");
            </script>
        </div>

        <div>Index</div>     

    </body>
</html>

When I call this same structure on another page, profile.html for example, the master structure does not work ! What am I doing wrong ?

  • look face sincerely was to work the load in this div, edit and put the path of index.php and where is the master.html, apparently is the path that is incorrect, otherwise I see another solution.

  • would like to know how the new content will be inserted in the inherited page ?

2 answers

2


Your error occurs due to missing Jquery reference.

Just include the reference that can be made via Cdn,

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

or via download that can be found here.

Look at this example I made.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <div id="new-header">

    </div>

    <div>Index</div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script>
             $("#new-header").load("page/master.html");
    </script>
</body>
</html>

2

All pages that you enter the "page/master.html" insertion code must contain Jquery. Place the following code inside the head tag:

<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>

Or download jquery and change src to your location.

If you don’t want to put the code on every page that you want to insert, you can replace your "page/master.html" insertion script with a php include:

<?php include("page/master.html") ?>

Or an html iframe:

<iframe src="page/master.html"></iframe>

Browser other questions tagged

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