include html file within an html file
I'm trying to include an html file within another html file. the include acts as a menu and footer. i'm using the current include syntax but my html data is not displaying on the page. my include files sit at the root. i've tried:
<!--#include virtual="header.html" --> <!--#include file="navigation.html"--> <html> <head> <title>test</title> </head> <body> <!--#include virtual="header.html" --> <!--#include virtual="navigation.html"--> <p>test<p> <!--#include virtual="footer.html"--> </body> </html>
Check if your server has server-side includes (SSIs) enabled.
edit: Also, you should remove the first set of includes that come before the
html tag - that's invalid.
Here is a simple PHP script you can use to include a snippet of HTML on any PHP-enabled web page: Save the HTML for the common elements of your site, such as the navigation, to separate files. For example, your Use the following PHP code to include that HTML in each page ( substituting your
Apache webserver? Do you have "mod_include" enabled? Do you have either in .htaccess or httpd.conf the setting "Options +Includes" set?
To get Solution working you need to include the file csi.min.js, which you can locate here. As per the example shown on GitHub, to use this library you must include the file csi.js in your page header, then you need to add the data-include attribute with its value set to the file you want to include, on the container element. Hide Copy Code
Includes are server side, you'll need to save the main file as an .asp file and work with it on a server (assuming your server is ASP enabled, your syntax certainly makes that look as if it's the case).
a lot of info lays here: http://www.boutell.com/newfaq/creating/include.html, if it runs in the server i would go for
<?php include("filename.html"); ?> since most of the servers also have php, if not you can always use .js
P.S. i won't mentions html possible problems since other answers i think mentioned all i know...
The page seen by a browser viewing a.html will consist of the contents of a.html before the include line, followed by the contents of b.inc, followed by the contents of a.html after the include line. Put the HTML for your navigation bar in a file like b.inc, and all your pages can show the exact same bar.
The Netscape Navigator frames extension (cf. Wikipedia's Framing article) and its successors allow you to write HTML pages that reference other pages for inclusion. The browser then assembles the viewed page by making multiple HTTP requests. Note:
- It's a horrible way to serve up webpages: there's no well-behaved document model for it. But it is fairly well supported by browsers. So this answer is for information's sake, not a recommendation; and
- It creates viewed pages by juxtaposition, not inclusion, so it's not really what you were after, semantically speaking. But you can use it to solve your problem: the menu and footer bars are mini HTML pages that sit next to the page containing the main content.
It’s extremely surprising to me that HTML has never had any way to include other HTML files within it. Nor does there seem to be anything on the horizon that addresses it. I’m talking about straight up includes, like taking a chunk of HTML and plopping it right into another.
@kapa I'm voting to re-open because (1) the linked question asks about best practices and this one asks a practical how-to question, (2) the linked question is about templates in general and this one is specifically about including the contents of an external file (which can have other uses beyond just templating), (3) The answers on that question and this question are totally different with
You should have a file named .htaccess in your web server's /public_html directory, or in another directory, where your html file will be and you will process one command inside it. Save this file with the name .htaccess and upload it to the server's main directory.
You can add as many html content as you want as columns or rows. For rows <frameset rows=”25%,25%,50%”>… this will give you 3 rows to include 3 html files. Similarly for columns <frameset cols=”25%,25%,50%”>… this will give you 3 cols to include 3 html files. For only one file to include use : <frameset row=”100%”>