简体   繁体   English

我要在所有页面上使用相同的固定标题-是否可以链接动态HTML或Javascript

[英]I want the same Fixed Header across all pages - Can I link dynamic HTML or Javascript

I have a website that is mostly done in HTML and CSS with some JS. 我有一个网站,大部分使用HTML和CSS以及JS完成。

Ive now set up a page where header is perfect to me - it is FIXED contains Divs with a Logo, a search bar and phone number. Ive现在设置了一个页面,该页面的标题对我来说很完美-它已修复,其中包含带徽标的Div,搜索栏和电话号码。 Underneath this div is a Navbar that is controlled by master Javacript file as a template and also the Navbar fades upon scroll with JS. 该div下方是一个Navbar,该Navbar由主Javacript文件作为模板进行控制,并且该Navbar在使用JS滚动时也会消失。

My question is how do I set it up so that the entire header with all that styling can be replicated on 80 pages and I just have to change it once? 我的问题是如何设置它,以便可以将所有带有所有样式的标头复制到80页上,而只需要更改一次即可?

I've tried this below - where an external page header1.html has the header code (of which has full html head, body, etc) but when I load it all, the page calls up the header1.html quickly and then disappears. 我在下面尝试过-外部页面header1.html具有标题代码(其中具有完整的html头,正文等),但是当我全部加载时,页面会迅速调用header1.html,然后消失。

<script src="//code.jquery.com/jquery-1.10.2.js"></script> in head

<div id="header"></div>
<script> 
  $("#header").load("header1.html"); 
</script> 

end body 端体

header1.html should NOT contain a full html document. header1.html不应包含完整的html文档。 Rather, it should just be the snippet of html code that you need for the header stuff. 相反,它应该只是标头内容所需的html代码段。

You can use php. 您可以使用php。 Place the content from the header in header.html, place te next code in every page where you want show the header. 将标题中的内容放在header.html中,在要显示标题的每个页面中放置下一个代码。

<?php include 'header.html'; ?>

Note: change your files from .html to .php 注意:将文件从.html更改为.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得此javascript变量以跨HTML页面工作? - How can I get this javascript var to work across HTML pages? 如何在我网站的所有不同页面上运行JavaScript函数? - How can I run a JavaScript function across all of my website different pages? 加载和.html(墙上的帖子)到不同的页面(所以我可以在所有要添加它们的页面上都有墙上的帖子),使用angular - Load and .html (wall posts) to different pages (so I can have wall posts in all the pages i want to add them) ,using angular 我如何在其余所有页面中具有第一页的相同页眉 - How can i have same header of first page in rest of all the pages 如何在我的网站上的所有页面上进行搜索 - How can I search across all pages on my website 如何编写 .html.erb javascript 函数来隐藏特定页面的标题? - How can I write .html.erb javascript function to hide header from particular pages? 我可以使用javascript隐藏Html链接吗? - Can I hide an Html link using javascript? 我想要从 javascript 到 php 跨不同域的发布请求。 CORS 错误,header 原点错误 - I want a post request from javascript to php across different domain. CORS error, header origin error 如何通过 JavaScript 链接两个页面? - How can I link two pages through JavaScript? HTML 页面 - 所有 HTML 页面中的顶部菜单(页眉)和页脚是否相同? - HTML Page - same top menu (header) and footer in all HTML pages?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM