Brandroid
Brandroid

Reputation: 266

Default HTML Page?

Alright, I don't know how exactly I'm going to phrase this, so bear with me here. Is there a way to set a default HTML page? Like is there a line of code that I can use on new html files to load a local .html file for almost a template?

Upvotes: 2

Views: 3315

Answers (3)

htmljenn
htmljenn

Reputation: 26

The default web page on a server must have the name index.html, index.htm or sometimes default.htm. It is possible to change the server to accept other file names as default files, but those are the most commonly used ones. What is the index.html page?

If you're asking how to make your web browser open a default page when you open it, this is usually called the "Home Page" and any file or page that you can visit in your browser you can assign as the home page.

If you're trying to create a template for a web page, there are many ways to do it. The PHP example listed above is one way. You can also do it with JavaScript. Write your HTML in document.write() calls inside a file named navigation.js and then place this script where you want that code displayed:

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

However, this is not unobtrusive and could cause problems. Another way to do it is with Server Side Includes. Write a file named navigation.ssi and then add the following SSI line to your HTML where you want the included file to display:

<!--#include virtual="/ssi/navigation.ssi" -->

You can also do it with ASP and other methods. I explain in more detail in my article How Do I Include One HTML File in Another?

Upvotes: 0

Aleksandr
Aleksandr

Reputation: 2321

Use any sever-side programming language to include header and footer parts of your default webpage. Example on PHP:

<?php
echo file_get_contents("header.html")
?>
Your page contents
<?php
echo file_get_contents("footer.html")
?>

Upvotes: 3

developerwjk
developerwjk

Reputation: 8659

You can set default html page in your webserver. But that's just if someone hits http://server/ with no page name it tells what page to use like http://server/index.html versus http://server/default.apx, etc. Has nothing to do with templates.

If you want to be able to include html files inside other html files, you probably need a serverside language like ASP, PHP, JSP. HTML itself doesn't have that capability, although some webservers might offer a custom tag that is translated on server-side for includes.

Upvotes: 0

Related Questions