I am using the following to get the active page url:
I am not sure if you want solution in Javascript. Here my suggestion Your Html code
<ul id="navigation">
<li class="current">
<a href="index.php?option=com_content&view=article&id=6&Itemid=109">Link 1</a>
</li>
<li>
<a href="index.php?option=com_content&view=article&id=6&Itemid=110">Link 2</a>
</li>
<li>
<a href="index.php?option=com_content&view=article&id=6&Itemid=111">Link 3</a>
</li>
</ul>
Javascript Code
url = 'http://www.domain-nane.com/index.php?option=com_content&view=article&id=6&Itemid=111';
// url = '<php echo curPageURL();?>';
var urlRegex =/Itemid=([0-9]+)/i;
var Itemid = url.match(urlRegex)[1];
// alert(Itemid);
var nodes = document.getElementById('navigation').childNodes;
var lis;
for(i=0; i<nodes.length; i++) {
if(nodes[i].nodeType == 1){
var lis = nodes[i];
var aElem = lis.childNodes[1];
var AItemId = aElem.href.match(urlRegex)[1];
if(Itemid == AItemId) {
lis.className = lis.className + " current";
}
}
}
Running Example http://jsfiddle.net/xdsUm/3/
its simple
<li class="<?php if($Itemid == $_REQUEST['Itemid']) { echo 'active'; } ?> ">
This will look like this is in HTML
<li class="active">
you are doing wrong thing
simple way is below..
In your URL Itemid
is unique, so its better to do this in following way
<li <?php if($Itemid == $_REQUEST['Itemid']) { echo class='current'; } ?> >
<a href="index.php?option=com_content&view=article&id=6&Itemid=109">Link 1</a>
</li>
<li <?php if($Itemid == $_REQUEST['Itemid']) { echo class='current'; } ?> >
<a href="index.php?option=com_content&view=article&id=6&Itemid=110">Link 2</a>
</li>
<li <?php if($Itemid == $_REQUEST['Itemid']) { echo class='current'; } ?> >
<a href="index.php?option=com_content&view=article&id=6&Itemid=111">Link 3</a>
</li>
I think that you want something like this:
<ul id="navigation">
<li <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="current"';?>><a href="index.php">Home Page</a></li>
<li <?php if (strpos($_SERVER['PHP_SELF'], 'about.php')) echo 'class="current"';?>><a href="about.php">About Me</a></li>
<li <?php if (strpos($_SERVER['PHP_SELF'], 'contact.php')) echo 'class="current"';?>><a href="contact.php">Contact Me</a></li>
<li <?php if (strpos($_SERVER['PHP_SELF'], 'portfolio.php')) echo 'class="current"';?>><a href="portfolio.php">My Work</a></li>
</ul>
I hope this will help you!
PS: index.php, about.php, contact.php and portofolio.php must be replaced with your pages links.