Menu
Posted: 06 September 2007 04:10 PM   [ Ignore ]
Newbie
Rank
Total Posts:  1
Joined  2007-09-06

I’m looking for some help to show how to code the css to show what page I’m on.
I would like there to be a tab showing which page I’m on. 
I don’t care for there to be any type of roll over or such.

Any help would be greatly appreciated.

Profile
 
 
Posted: 16 November 2007 12:10 PM   [ Ignore ]   [ # 1 ]
Member
Avatar
RankRankRank
Total Posts:  52
Joined  2007-11-08

I use this code normally for having my active page’s link highlighted.. Found it on net, the author is Paul @ Yellow Pencil .com..Once you’ve attached this js to your pages, you only need to style the class .active_menu so that it has the green background and your work is done.. Hope it helped

function scriptInit() {
if (!document.getElementById) {
  return;
  }
}
function addEvent(elm, evType, fn, useCapture) {
  if (elm.addEventListener) {
  elm.addEventListener(evType, fn, useCapture);
  return true;
  } else if (elm.attachEvent) {
  var r = elm.attachEvent(‘on’ + evType, fn);
  return r;
  } else {
  elm[‘on’ + evType] = fn;
  }
}
function checkActive() {
  var a = document.getElementsByTagName(“a”);
  if ([removed].href.substr(location.href.length - 1, 1) == ‘/’) {
      //var loc = [removed].href + ‘index.html’;
  }
  else {
      var loc = [removed].href;
  }
  for(var i=0; i < a.length; i++) {
      if (a.href == loc) {
        a.setAttribute(“class”, “active_menu”);
        a.setAttribute(“className”, “active_menu”);
      }
  }
}
addEvent(window, ‘load’, checkActive, false);

Profile
 
 
Posted: 18 November 2007 06:06 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  9
Joined  2007-11-12

I don’t believe there is a need to use programming here.  I am assuming that you are using classes for the menu and it probably looks something like:

<ul>
    <li>Home</li>
    <li>About Us</li>
    <li>Menu</li>
    <li>Contact Us</li>
    <li>Blog</li>
</ul>

You may have it wrapped in a div or however you have it styled. All you need to do to create an active state is give it an id.
<li>Home</li>

and then style your active button with
a#active {}

this is what it would look like
<ul>
    <li>Home</li>
    <li>About Us</li>
    <li>Menu</li>
    <li>Contact Us</li>
    <li>Blog</li>
</ul>

and on the other pages move the corresponding active to the given link for that page.

Profile
 
 
Posted: 19 November 2007 01:31 PM   [ Ignore ]   [ # 3 ]
Member
Avatar
RankRankRank
Total Posts:  52
Joined  2007-11-08
shadowdesigner - 18 November 2007 06:06 PM

I don’t believe there is a need to use programming here.  I am assuming that you are using classes for the menu and it probably looks something like:

<ul>
    <li>Home</li>
    <li>About Us</li>
    <li>Menu</li>
    <li>Contact Us</li>
    <li>Blog</li>
</ul>

You may have it wrapped in a div or however you have it styled. All you need to do to create an active state is give it an id.
<li>Home</li>

and then style your active button with
a#active {}

this is what it would look like
<ul>
    <li>Home</li>
    <li>About Us</li>
    <li>Menu</li>
    <li>Contact Us</li>
    <li>Blog</li>
</ul>

and on the other pages move the corresponding active to the given link for that page.


And what shall he do in case he has not 5 but 50 pages?? should he be doing the same as you said?? One mustn’t always think of today only, maybe tomorrow you wish to expand your menu and/or add new links, other menus, and if you do it in a static way, you’ll have to do the changes everytime you add a new page..

Profile
 
 
Posted: 19 November 2007 03:54 PM   [ Ignore ]   [ # 4 ]
Newbie
Rank
Total Posts:  9
Joined  2007-11-12

Actually the original question was

“I’m looking for some help to show how to code the css to show what page I’m on”

It sounded to me that they are wanting to work with the CSS and HTML. For some Javascript is not an option.  And I agree you do need to consider and think for the future but sometimes that future only consists of a few menu items and not 50.

Profile
 
 
Posted: 22 November 2007 04:37 PM   [ Ignore ]   [ # 5 ]
Newbie
Rank
Total Posts:  7
Joined  2007-11-21

I would only use a scalable javascript solution when it’s appropriate and needed. If the poster doesn’t have the expertise or understanding and the site is small then go w/ just manually adding a class, not as elegant but easy to maintain and update and isn’t dependant on the user having javascript enabled.

Profile