如何在一个地方编写导航栏,并仅使用html/css/js在所有页面上使用它

How to write a navigation bar in one place and use it across all pages with just html/css/js

本文关键字:css html js 一个 导航 方编写      更新时间:2023-09-26

我肯定记得做过一次,但不记得怎么做了。

我想做的是在一个地方用html编写一个导航栏,让每个页面都从文件中获取html代码,并在页面加载时将其添加到页面中。PHP不起作用(我怀疑我需要一个服务器来运行PHP,我甚至不打算使用它)

类似于:

导航栏文件:

<div>
    other code...
</div>

主网页文件:

<html>
    <header>
    </header>
    <body>
    </body>
    <div>
        put navbar file code here...
    </div>
</html>
<iframe src="file_with_only_div_content.html" allowtransparency="true" frameborder="0"></iframe>

你的意思是http://en.wikipedia.org/wiki/Server_Side_Includes服务器端包括?

<!--#include virtual="../quote.txt" -->

这些支持了吗?

为了让web服务器识别启用SSI的HTML文件并执行这些指令,文件名应以特殊扩展名结尾,默认为.shtml、.stm、.shtm,或者,如果服务器配置为允许这样做,则设置文件的执行位