如何在不使用 iFrames 或 PHP 的情况下以简单的 HTML/CSS 或 XML 重复菜单?
对于这个最终的新问题感到抱歉。我想创建一个菜单,而不必在每个网页上重复菜单的代码。我过去曾使用 iframe 完成此操作,但我知道不推荐它们。我对 HTML 和 HTML 有相当多的了解。 CSS,但我觉得我在这里错过了一些大东西。
我也不是在寻找我认为代表的 PHP 解决方案:
<?php include("navigation.html"); ?>
是否有我可以遵循的好的教程?我听说这可以通过 XML 来完成,但我一直无法找到我正在寻找的确切内容,并且过去对此没有任何了解。
在我认为相关的问题中,我希望能够将我的谷歌分析代码放在我的索引页面上,并让它引用整个网站的页面,而不仅仅是索引。再说一遍,我在这里缺少什么?我是否需要使用某种内容管理系统来完成这个稍微动态的任务?我不这么认为......
感谢您的帮助,如果我能更好地澄清我的问题,请告诉我!
sorry for this ultimately newb question. I want to create a menu and not have to repeat the code of the menu on every single web page. I have done this with iframes in the past, but I know they aren't recommended. I have a pretty decent knowledge of HTML & CSS but I feel like I am missing something big here.
I am also not looking for the PHP solution which I believe is represented by:
<?php include("navigation.html"); ?>
Is there a good tutorial I can follow? I've heard this can be done with XML but I haven't been able to find what I am looking for exactly, and don't have any knowledge with it in the past.
In what I think is a related problem, I want to be able to place my google analytics code on just my index page and have it reference the entire website of pages, not just the index. Again, what am I missing here? Do I need to be using a content management system of some sort to pull off this slightly dynamic task? I don't think so...
Thanks for your help and please let me know if I can clarify my question any better!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不太确定除了 .php 之外还有哪些选项。我不确定为什么你会避免使用 PHP,除非服务器不支持它,因为执行包含非常简单(你实际上甚至不需要了解 PHP 来执行此操作,除了
include
声明)。对于您的分析代码,您可以将其放入 .js 文件中,然后将其包含在每个页面上:
希望这至少有点帮助。
I'm not really sure what options you have other than a .php include. I'm not sure of why you would be avoiding PHP unless the server didn't support it, as it's very simple to do an include (you really don't even need to know PHP to do this except for the
include
statement).For your analytics code, you could put this in a .js file and just include it on every page:
Hope this was at least slightly helpful.
JavaScript 怎么样?您可以编写一个 Javascript 文件,将其包含在您希望显示菜单的每个页面上。 JavaScript 可以读取包含菜单项的 XML 并生成 HTML 来显示菜单。
使用 JS 解析 XML 文档
http://www.w3schools.com/Xml/xml_parser.asp
jQuery菜单解决方案
http://speckyboy.com/ 2010/12/01/15-超级简单-jquery-menu-and-navigation-plugins/
How about javascript? You could write a Javascript file that is included on each page that you wish to display the menu. The javascript could read an XML that contains your menu items and generates HTML to display the menu.
Parse and XML document with JS
http://www.w3schools.com/Xml/xml_parser.asp
jQuery menu solutions
http://speckyboy.com/2010/12/01/15-super-simple-jquery-menu-and-navigation-plugins/
如果您没有 .htaccess 文件,请创建一个文件 cal 并将其命名为“.htaccess”,
然后将此代码放在上面
if you don't have .htaccess file, create a file cal and name it ".htaccess"
and put this code on it
如前所述,使用服务器端包含。几乎所有主要网络服务器都支持它们,因此甚至不需要 php。
查看以下文章:
祝你好运
Use server side includes as mentioned already. They are support by pretty much all major webservers so php is not even required.
Check out the following articles:
Good Luck
为什么不想使用 PHP?它可以通过 JavaScript(使用 AJAX)来完成,但如果您选择这条路线,您需要为搜索引擎提供一种抓取您网站的方法。
在 PHP 中使用 include 来实现这一点很简单,并且只需要很少的知识。比使用 JS 更简单、更高效。另外,我看不出 XML 在这里有什么帮助,除非你用 JS 读取它(在这种情况下你会遇到上面提到的同样的问题。)
Why don't you want to use PHP? It can be done with JavaScript (using AJAX), but you need to provide search engines with a way to crawl your site if you go that route.
Using includes in PHP to achieve this is simple and requires extremely little knowledge. Much easier and more efficient than doing it with JS. Also, I don't see how XML would be of any help here unless you read it in with JS (in which you'd have the same issue mentioned above.)