如何从不同的HTML文件中调用FOOTER和NavBar?

时间:2016-08-31 07:55:02

标签: html css

我正在创建一个简单的网页,其中我希望所有静态部件(如我的网页的NavBar和Footer)都位于单独的HTML文件中。

因此,每当我创建一个新页面时,我只需要调用它或链接它,以减少我的代码行和加载时间。我怎么能在这里做?请帮帮我。

我想做这样的事情:

enter image description here

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HACMS</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/Site.css">
    <link rel="stylesheet" type="text/css" href="css/dashboard-navbar.css">
    <link rel="stylesheet" type="text/css" href="css/footer-style.css">
    <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css" />
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/csi.min.js"></script>
    <script type="text/javascript" src="js/csi.js"></script>
    <script type="text/javascript" src="js/bootstrap.js"></script>
    <script> $("#includedContent").load("sampleFooter.html"); </script> 

</head>
<body>
    <h1>THIS IS THE BODY</h1>
     <!-- THIS IS MY NAVBAR -->
        <nav class="navbar navbar-inverse navbar-fixed-top navbar-custom" role="navigation">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#"><img src="css/images/SSILogo.png" alt="SMESoft Inc." /></a>
                </div>
               <div class="collapse navbar-collapse navbar-ex1-collapse">

                    <ul class="nav navbar-nav navbar-right navbar-user">

                        <li><a href="#" class="hvr-underline-from-center"><i class="fa fa-sign-in" aria-hidden="true"></i>&nbsp;&nbsp;Log Out</a>
                        </li>
                    </ul>
            </div>
        </nav>
        <br>
        <br>

        <!-- THIS IS MY FOOTER -->
        <footer>
         <div class="footer">
                <div class="container">
                    <div class="row">
                        <div class="col-lg-5  col-md-4 col-sm-4 col-xs-4">
                            <h3> Company Background </h3>
                            <p>
                                SMESoft Inc. (SSI) is a duly registered company in the Philippines Securities and Exchange Commission (SEC). Established in 2008 and registered in 2011, the company has developed its product line of Business Management Solutions for Small to Medium Enterprise.
                                Part of the company's expansion is the acquisition of authority to distribute the products and trainings of the internationally renowned RMC Project Management Inc. headquartered in Minnesota, USA. It encompasses product distribution and training conduct with RMC trademark across the country and nearby territories (subject to RMC approval).
                                Two years ago, SSI started extending an advocacy campaign to raise awareness of the Project Management discipline which the founder believes will benefit the people by applying the necessary skills and concepts for a better future.

                            </p>
                        </div>

                        <div class="col-lg-3  col-md-3 col-sm-4 col-xs-4 ">
                            <h3> Keep Connected </h3>
                            <ul class="social">
                                <li> <a href="#" class="icoFacebook"> <i class=" fa fa-facebook"></i> &nbsp;&nbsp;Like Us on Facebook</a></li>
                                <li> <a href="#" class="icoInstagram"> <i class="fa fa-instagram"></i> &nbsp;&nbsp;Follow Us on Instagram</a> </li>
                                <li> <a href="#" class="icoLinkedin"> <i class="fa fa-linkedin"></i> &nbsp;&nbsp;Follow Us on LinkedIn</a></li>
                                <li> <a href="#" class="icoPinterest"> <i class="fa fa-pinterest"></i> &nbsp;&nbsp;Follow Us on Pinterest</a></li>
                                <li> <a href="#" class="icoTwitter"> <i class="fa fa-twitter"></i> &nbsp;&nbsp;Follow Us on Twitter</a></li>
                            </ul>
                        </div>

                        <div class="col-lg-4 col-md-3 col-sm-4 col-xs-4">
                            <h3> Contact Information </h3>
                            <ul>
                                <li>
                                    <span class="fa fa-home" aria-hidden="true"></span>
                                    &nbsp;&nbsp;Unit 511-512 VGP Center,
                                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Legaspi Ayala Avenue,</p>
                                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Village Makati City </p>
                                </li>

                                <li>
                                    <span class="fa fa-mobile" aria-hidden="true"></span>
                                    &nbsp;&nbsp;+63 933.049.8890 (SMART)
                                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+63 906.297.0995 (GLOBE)</p>
                                </li>

                                <li>
                                    <span class="fa fa-phone" aria-hidden="true"></span>
                                    &nbsp;&nbsp;886-9775 | 512-5955
                                </li>

                                <li>
                                    <span class="fa fa-envelope-o" aria-hidden="true"></span>
                                    &nbsp;&nbsp;inquire@smesoft.com.ph
                                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;marketing@smesoft.com.ph</p>
                                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sales@smesoft.com.ph</p>
                                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;support@smesoft.com.ph</p>
                                </li>
                            </ul>
                        </div>

                    </div>
                    <!--/.row-->
                </div>
                <!--/.container-->
            </div>
            <!--/.footer-->

            <div class="footer-bottom">
                <div class="container">
                    <center><p>&copy; 2016 SMESoft Inc. All Rights Reserved</p></center>
                </div>
            </div>
        </footer>
</body>
</html>

3 个答案:

答案 0 :(得分:1)

footer.html /保存在部分文件夹

Gawa ka ng partial na文件夹。 Doon mo i-save ang footer.html

<footer>This is a footer</footer>

JS(把它放在所需的页面上)

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
    if (xhttp.readyState == 4 && xhttp.status == 200){
        document.body.innerHTML += xhttp.responseText; // you can change the target. As long as you append xhttp.responseText. It will work fine.
    }
};
xhttp.open('GET', 'partial/footer.html', true); // note: link the footer.html
xhttp.send();

示例:假设您已经使用index.html

只需将JS代码放入索引即可。

<body>
    <script>
        var xhttp = new ....
    </script>
</body>

这是没有缓存的基础。如果要创建路由,则需要缓存。测试。干杯。希望能帮助到你。

答案 1 :(得分:0)

表示$("#includedContent")的部分是指页面上的ID。

所以页脚应该有id="includedContent"。那么&#39; load()&#39;将来自sampleFooter.html的内容放入该ID。

答案 2 :(得分:-5)

您可以使用iframe Element

<iframe src="name.html"></iframe>