问题
How can I import an HTML file within my HTML file? I will prepare header.html and footer.html files separately and every file that I want to include them I want to import them into my HTML file.,
EDIT: I see that solution based on SSI technique. I use Ubuntu and Tomcat 7.0.11. How can I enable SSI at tomcat?
回答1:
There are many solutions to this problem. You can write simple JavaScript code to include parts of your page on load, you can enable SSI on your web-server, and finally you can use any server-side language to dynamically include chunks of any page for output. Your choice depends on how dynamic your web-site is.
回答2:
You can include html files using frames or iframes. If you're using a server side language such as PHP or ASP you can do this without frames using includes.
回答3:
If you wanted to strictly use HTML (and assuming you are using JS too) I would do the following:
You could have a <div>
for the header, I will call it <div id="header">
.
Using jQuery we could say something like: $('#header').load(---html file---);
. Aside from the pain it might be to include the JS file in all pages, it will allow you to make changes to the header globally throughout your application.
来源:https://stackoverflow.com/questions/7103793/how-can-i-import-an-html-file-within-my-html-file