开发者

Insert Code Into HTML

I have a web site that gets a new page every couple weeks, and that means I need to update the menu to have the new page in every single one. I'm wondering if there is a way to hav开发者_如何学Pythone an external text or .htm file that I can basically insert into the web page. That way I can put the menu in the external file and call it wherever I want it. So I only have to edit one thing when I get a new page.

Thanks in advance.

Edit: This is a drop-down menu with ul and li tags with an external style sheet for them. So this needs to work for that too. Thanks


Have a single HTML page like so:

<html>
<head></head>
<body>
HTML OF LINKS HERE
</body>
</html>

Then save it as my_links.html and into the page you want to insert it... do the following. Copy and paste the whole page and it as FILENAME.PHP and then use this code:

<?php include("my_links.html"); ?>

Congratulations, you have just used PHP! Learn more about the including pages here.


This is very easy and common to do on sites that use a server-side language behind them (PHP, ASP.NET, etc.)

If you don't want to use a server side language, than an <iframe> is your only option.


If you want to use HTML, and only html (no server side programming or javascript), you can use Server Side Includes embedded into your html files. Your web server may need to be configured to accept them.


If you are using server side include and you had navigation in a separated file, yes you can just edit things separate.


You can also do this using jQuery.

$('#elementid').load('page.html');

http://api.jquery.com/load/

But this will not be SEO friendly. Also if someone has scripts turned off in their browser, then this will not work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜