开发者

How to repeat a menu without using iFrames or PHP in simple HTML/CSS or 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!


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.)


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:

  1. http://en.wikipedia.org/wiki/Server_Side_Includes
  2. http://httpd.apache.org/docs/1.3/howto/ssi.html (from apache, note no php needed)
  3. http://www.boutell.com/newfaq/creating/include.html

Good Luck


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:

<script type="text/javascript" src="analytics.js"></script>

Hope this was at least slightly helpful.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜