Reply To: Set home page link to active, when no page is selected

Home Forums Older releases 0.9.x Set home page link to active, when no page is selected Reply To: Set home page link to active, when no page is selected

#2387
admin
Keymaster

You seem to be using some custom JS that doesn’t work properly:

        $(function(){

            var url = window.location.pathname, // in real app this would have to be replaced with window.location.pathname 
                urlRegExp = new RegExp(url.replace(/\/$/,'')); // create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there

            // now grab every link from the navigation
            $('#centeredmenu a').each(function(){
                // and test its href against the url pathname regexp
                if(urlRegExp.test(this.href)){
                    $(this).addClass('active');
                }
            });

        });

To fix it, change the following line:

urlRegExp = new RegExp(url.replace(/\/$/,'')); // create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there

like this:

urlRegExp = new RegExp(url.replace(/\/$/,'') || "index.php"); // create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there

and then set your link like this:

<li><a href="index.php">Home</a></li>

Cheers!

Register

You will be emailed a link to set your password.

Login

Lost password?