HTML inherit main html with menus - html

I want to build a website with 30 html pages. They all are going to have left menu and top menu always the same so i would like to define those menus in only one html and inherit that html in all other html pages.
Is this possible? How is it done?
I was looking for a solution without using php.
Regards,

You could use frames, but that's a bad method as its old and outdated now.
Your better solution would be to use PHP and have the menus as separate files and just 'link' them to the main page by using the include function
Ie
<html>
<head>
<?php include 'head.php'; ?>
</head>
</html>
And then your head.php file could include your title tag and anything else that may go in the head tag.
That way you only have to make one change to the site title for it to affect all the pages the include is featured in.

Related

How to load a link in an iframe in the whole browsertab?

I want to put my header in an iframe-element so that I can change the headers of all subpages of my website in one css. But when I click on a link in the header, the new page loads only in the iframe element. Is there any way to make the new page load in the whole browsertab rather than in the iframe?
The link target determines which viewport a link opens in. To open in the parent window use _parent.
...
That said, using iframes to include common content is a really ugly approach to the problem with accessibility and SEO implications. I'd strongly suggest you consider using a Static Site Generator or one of the other options in this answer instead.
You can link a css file in the head part of your html code like so:
<head>
<link rel="stylesheet" href="your-header-styles.css">
</head>
So you don't have to use iframes.
You can't access or control the parent page from within an iframe.
If you really wanna do it the old-school way, you can use a frameset. But this isn't supported anymore in HTML5.

Include menu into html files

I have a web site of more than 20 pages, all using the same dropdown menu. Currently, each page contains redundant HTML code for the menu, so if I want to change one thing in a menu, I have to change it for all the pages. I am using plain html/css and some javascript for my site. Is there a way to have my dropdown menu all in one file and include the reference to that file for all 20 pages?
I tried using the <embed> element to include the menu, but it did not work out for me since I cannot adequately align it as it leaves a large empty area right below it to allow for dropdown options. Not sure what is the best way to handle that
As suggested by Quetin Veron in the comment, PHP include statements are the best way to deal with it.
However, in case you're not interested in writing backend code, you can do that using JavaScript by parsing a json or an ini file/text in your script and converting it into the required links on the menu.
[Do note that you'll still have to use JavaScript for that]
If you'd not even prefer to use JS (Not recommended), you can use an iframe as the navigation menu
When you do that, add <base target="_parent"> in the head section of your iframe.
And then, in all other pages, add <iframe src="menu.html"></iframe> and replace menu.html with the path to the menu.
I hope this helps. However, please note that this just is a workaround if you wish to use frontend technologies only.
Otherwise use <?php include "menu.php";?> for PHP or for Node with EJS, use <%include "menu.ejs";%>

Link html using source

I have tried:
<html src="navbar.html"></html>
I have a file called navbar.html
Is there any way I could make it appear on every page I have?
I will be changing the navbar a lot throughout my website and I don't want to change it in all my 20+ pages. How can I make this one file appear in every page?
Would it be possible to make it in html rather than jquery and append it to every page?
something similar to
<script src="file.js"></script>
But html src
Why not just use PHP? As long as you're developing on a server (as PHP is server side) you can essentially change .html files to .php and include a file for the navbar. For example:
<?php include 'navbar.php'; ?>
Look up PHP include at http://php.net/manual/en/function.include.php. It will do exactly what you want. All you do is include the file on every page and it will be reflected in every page .
Visit our HTML tutorial
The href attribute specifies the destination address (http://www.w3schools.com/html/) of the link.
The link text is the visible part (Visit our HTML tutorial).
Clicking on the link text will send you to the specified address.
http://www.w3schools.com/html/html_links.asp

Same menu on every page

I have a website that has menu on every page. But, When I try to add new link on the menu, I
had to add the link on every page individually. So, I used HTML and CSS like this so I just have to edit one thing, but it will just show up as "Home" with "a" tag on it instead of showing "Home" as hyperlink.
<!DOCTYPE html>
<html>
<head>
<style>
.menu:after{
content: "HomeGames";}
</style>
<title>Page</title>
</head>
<body bgcolor="#cccccc">
<center>
<div class="menu"></div>
<center>
</body>
</html>
create a page call
menu.php and put the menu, for example with your code
HomeGames;
then in your index.php
<?php
include('menu.php');
?>
You cannot do that using CSS because the style would have to alter the DOM. CSS is simply not designed and not legitimized to alter the DOM.
CSS content property: is it possible to insert HTML instead of Text?
What you probably should do is using a server-sided pre-processing language like PHP to go with templating.
Another solution would be using jQuery (javascript):
$('.menu').prepend('Home');
That is the wrong way to go about doing something like that. What you really need is to use a language that can make templating possible. I would recommend learning PHP, it makes stuff like that much easier. With PHP, you could have a file called menu.php, with the HTML markup for the menu inside the file, and then just type include "menu.php"; when you need it. PHP (and similar languages) can do so much more than that, you won't regret learning it.
Yikes, that is a really messy way to do it. You don't say weather you can or can't... but I really recommend using PHP for this. Create your menu in a PHP file, say 'menu.php' and include it like this
require_once("menu.php");
You will also have to change the file you put this in from .html to .php. As far as I know there is no performance issues with your method, and while you are solving your problem by putting the link in CSS, this sort of goes against everything CSS stands for. The content attribute is mainly for inserting certain characters to be styled differently.. like a custom bullet or something.
PHP is the best way to go about this, as other have mentioned. Javascript can accomplish this, but it wouldn't break gracefully. If the Javascript didn't work or was turned off, you would be left without navigation.
I thought I would just mention some other possibilities.
iframe:
<iframe src="/nav.html" seamless></iframe>
seamless isn't compatible with older browsers, but you can fix that with css.
SSI:
<!--#include virtual="/nav.html" -->
file would have to be saved as .shtml or the server configured to parse html for ssi

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 have 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.