JavaScript, menu+php ?

Y

Yves Lange

Hello i wrote a little script in JavaScript which makes my menu dynamic.
The menu can move with the window while the user moves up or down. But
the problem is that when a user click on a link (of this menu) i want
that the background of the cell stay in a specific color which will be
useful for the user to know which page he is reading. How can i do that ?

Thanks
---------------------------------------------------------
<script>
target5 = '_self';


haut5 = 10;
largeur5 = 10
color50 = "#333333";
color51 = "#555555";
color52 = "#838383";
color53 = "#FFFFFF";

menu5titre = new Array;
menu5lien = new Array;

menu5titre[0]= '-home'
menu5lien[0]= 'index.php'
menu5titre[1] = '-info coaching';
menu5lien[1] = 'index.php?p=info';
menu5titre[2] = '-contrat individuel';
menu5lien[2] = 'index.php?p=contrat-individuel';
menu5titre[3] = '-curriculum vitae';
menu5lien[3] = 'index.php?p=cv';
menu5titre[4] = '-contact';
menu5lien[4] = 'index.php?p=contact';

document.write('<STYLE TYPE="text/css">#menu5 {
position:absolute;top:'+haut5+';left:'+gauche5+'; }</STYLE>');

ie4=document.all
ns6=document.getElementById&&!document.all
ns4=document.layers

function placeMenu5() {
if (ie4) {menu5.style.pixelTop=document.body.scrollTop+haut5}
else if (ns6)
{document.getElementById("menu5").style.top=window.pageYOffset+haut5}
else if (ns4)
{eval(document.menu5.top=eval(window.pageYOffset+haut5));}
if(ie4 || ns6 || ns4)
setTimeout("placeMenu5()",1);
}

window.onload = placeMenu5;
document.write('<SPAN ID=menu5><table bgcolor="'+color50+'"
border=0 cellspacing=1 cellpadding=0 WIDTH=150><tr



/////////////////////////////
Here is the cell that i want
colored while reading a document.
I mean, only the specific line
////////////////////////////

ALIGN=center><B>Menu</B></TD></TR>')
for(a=0;a<menu5lien.length;a++)
{
document.write('<TR bgcolor='+color51+'><TD
onMouseOut="this.style.background=\''+color51+'\'"
onMouseOver="this.style.background=\''+color52+'\'"
STYLE="cursor:pointer"
onClick="window.open(\''+menu5lien[a]+'\',\''+target5+'\')"><FONT
FACE="Verdana, Arial" SIZE=1><B><A HREF="'+menu5lien[a]+'"
TARGET="'+target5+'"
STYLE="text-decoration:none;color:'+color53+'">'+menu5titre[a]+'</A></B></FONT></TD></TR>');
}
document.write('</TR></TABLE></SPAN>')
</script>
 
N

Neredbojias

Hello i wrote a little script in JavaScript which makes my menu
dynamic. The menu can move with the window while the user moves up or
down. But the problem is that when a user click on a link (of this
menu) i want that the background of the cell stay in a specific color
which will be useful for the user to know which page he is reading.
How can i do that ?

Use the hash and attach it to the url.
 
R

Rik

Yves said:
Neredbojias a écrit :

Cell? Since when is navigation tabular data? I'd use a ul.
I used PHP...

Quick & easy solution:
I have several pages qith unique names, which are valid classnames.
On every pageload the class of the body is set to that name, and in the list
(and elsewhere), the li's have also classes. The following CSS takes care of
the rest:

..page1 .nav_page1{background-color: #020202;}
..page2 .nav_page2{background-color: #020202;}
..page3 .nav_page3{background-color: #020202;}

Offcourse, if you're building the page using PHP, nothing stops you to make
a class "selected", and check which page is requested with PHP. Just attach
the class to the navigation item of the loaded page.

Grtz,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top