|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Web Coding | |
Nav Menu for all pages of site
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Intel Overclocker
![]() |
I'm new to all this, but I'm making a personal website for a class. I've found some code for a really great javascript nav menu to go on the left side of my page. I want this on every page, but I don't want to have to update each individual file each time I add an item to the menu. What is the best way to achieve this?
__________________
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||
|
makin' the big noise
![]() |
The easiest would be to use HTML frames. Have one centeral frame in the center of the page (index.html) where your actual content goes, then have the links in the Java navigation bar point to that specific frame. (So that news.html or whatever your content is shows up in the centeral frame, while the rest of the page, I/E the nav bar, stays the same.) I'm not as good with HTML as I used to be, but I could probably dig up one of my old sites if you wanted to see some of the code.
EDIT: Hre is a very complicated, but good guide on how to properly set up frames. http://www.w3.org/TR/html4/present/frames.html (I suggest using Frontpage, it makes them a breeze, if not totaly proper.)
__________________
There are two muffins in an oven. One muffin says, "Wow! Its getting hot in here!" The other muffin yells, "Ahhh! A talking muffin!!"
Like cars? Check out http://www.carforum.net! || Like dogs? Check out http://www.dogforum.org! I get a lot of private messages - I will get back to you, I promise!
Last edited by Chipp : 09-13-06 at 08:13 PM |
|||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
Intel Overclocker
![]() |
I thought about that. My prof has specifically asked us not to use frmaes though. If I can implement it smoothly then he won't mind but I'll avoid it if possible. Any other ideas?
__________________
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | ||||||||||
|
makin' the big noise
![]() |
Quote:
__________________
There are two muffins in an oven. One muffin says, "Wow! Its getting hot in here!" The other muffin yells, "Ahhh! A talking muffin!!"
Like cars? Check out http://www.carforum.net! || Like dogs? Check out http://www.dogforum.org! I get a lot of private messages - I will get back to you, I promise!
|
||||||||||
|
|
|
|
#5 (permalink) | ||||||||||||
|
Programmer
![]() |
chances are your school computers run .net 2.0 framework, and with that you can use what is called asp.net masterpages. You should be able to find some good documentation on the web for them. I use them at work. Basically a masterpage is a webpage that is the 'master' template which has an <asp:contentplaceholder> for where your other pages go, your other pages all load up inside the masterpage, so you only have to edit once. It is very simple to do in ColdFusion as well, but that is most likely not used in class.
I am sure there is a way to do this in php, but it has been so long since I have touched it I don't know off the top of my head. Here is a simple example (sorry if they are a bit long): MasterPage.master: Code:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.sidebar {
position:absolute;
background-color:yellow;
}
.content {
margin-left:100px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="sidebar">
<a href="Default.aspx">LINK1</a><br />
<a href="Default2.aspx">LINK2</a><br />
</div>
<div class="content">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
here is Default.aspx: Code:
<%@ Page Language="C#" MasterPageFile="MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Default Page <br /><br />BLA!<br />BLA!<br />BLA!<br />BLA!<br />BLA!<br />BLA!<br />
</asp:Content>
Code:
<%@ Page Language="C#" MasterPageFile="MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Page 2!?@#?!@#?! <br />;aklsdhjfkljasghdfkjahsdgf
<br />;aklsdhjfkljasghdfkjahsdgf <br />;aklsdhjfkljasghdfkjahsdgf
<br />;aklsdhjfkljasghdfkjahsdgf <br />;aklsdhjfkljasghdfkjahsdgf
<br />;aklsdhjfkljasghdfkjahsdgf <br />;aklsdhjfkljasghdfkjahsdgf
</asp:Content>
It is extremely ugly, but you get the point. fyi, this is an example in asp.net 2.0
__________________
"If there is a god, I hope he has a good excuse" :turd: Woody Allen
Last edited by BFRD : 09-14-06 at 07:22 AM |
||||||||||||
|
|
|
|
|
#6 (permalink) | |||||||||||||
|
Intel Overclocker
![]() |
well, i achieved the desired effect with an iframe. problem is I can't link directly to the page and already have the iframe opened to a specific link. Working on that now.
__________________
|
|||||||||||||
|
|
|
|
|
#7 (permalink) | ||||||||||||
|
Programmer
![]() |
You will only link to the main page that has the iframe within it. The other pages will be rendered in the iframe only, the url will never change.
Main page (with navigation): Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>TEST</title>
<style type="text/css">
body {background-color:gray;}
.sidebar { position:absolute; top:0; left:0;}
.content { margin-left:100px; width }
</style>
</head>
<body>
<div class="sidebar"><br /><br />
<a href="#" onclick="document.getElementById('iframe').src='iframe2.htm';">PAGE1</a><br />
<a href="#" onclick="document.getElementById('iframe').src='iframe.htm';">PAGE2</a><br />
</div>
<div class="content">
<iframe id="iframe" scrolling="no" style="border:0" frameborder="0" src="iframe.htm" width="100%" height="100%"></iframe>
</div>
</body>
</html>
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body style="background-color:Blue;">
</body>
</html>
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body style="background-color:Lime;">
</body>
</html>
__________________
"If there is a god, I hope he has a good excuse" :turd: Woody Allen
|
||||||||||||
|
|
|
|
|
#8 (permalink) | |||||||||||||
|
Programmer
![]() |
All you need to do is place the javascript in a separate file (e.g. navbar.html) and just include it on every page using PHP:
Code:
<?php include "www.yoursite.com/navbar.html"); ?>
__________________
Info: Static Electricity How To: Tweak windows to show file extensions How To: Get around Internet Explorer's rendering bugs (for web coders) ![]() "You're never late 'till you show up"
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|