How to store nav bar in one file?

前端 未结 5 1477
囚心锁ツ
囚心锁ツ 2021-01-30 11:39

I have a navigation bar for my website:

    
  • Home
5条回答
  •  [愿得一人]
    2021-01-30 11:48

    Update @AlienWebguy pointed out that these solutions will hurt your rankings in search engine results. If you care about that, don't use them. But in my opinion, as valid options, they are worth knowing about.


    If a server-side include (using PHP or some other language) is not an option you could do it using :

    1. Frames
      In all your pages, include an iframe (styled to be without borders or scrollbars) and set the src to be an HTML file that holds your navigation markup. Of course, you're going to run in trouble with following links and you'll probably have to resort to JavaScript in order to get the 'right' behaviour. This is probably not worth the effort. To follow the links correctly, you'll need to use the target attribute in your navigation links to _top (or perhaps _parent). This is probably the simplest solution that should work even in user agents without scripting support.

      For example, your page will look like this: