0

I have a problem with the quick launch menu, it doesnot shows the correct active page when using querystrings in the urls.

Lets assume I have the following urls in quicklaunch items:

  1. /default.aspx
  2. /default.aspx?ID=1
  3. /default.aspx?ID=2
  4. /default.aspx?ID=3

For every visited link (item 1-4), item 1 is shown as active.

Is there an OOTB solution to fix this?

2 Answers 2

0

i solved it with client script (needs jquery). Better solutions are welcome.

$(document).ready(function(){               
    $(".ms-selectednav").removeClass("ms-selectednav");
    var query = window.location.pathname.split('/').pop() + location.search
    var link = $("a[href*='" + query + "']:first");
    var table = $(link).parent().parent().parent().parent();
    link.addClass("ms-selectednav");
    table.addClass("ms-selectednav");                       
});
1
  • This seems to not work for me, since the class "ms-selectednav" is applied on page Title and not left navigation. Commented Jun 9, 2017 at 12:21
0

Here is one that works on office 365. Just add to a script editor webpart. Not tested so much yet but seems to work for me.

    function fixLeftNavSelection() {
        var leftNavBar = document.getElementById("DeltaPlaceHolderLeftNavBar");
        var selectednav = leftNavBar.getElementsByClassName("ms-core-listMenu-selected")[0];
        if (selectednav !== undefined) {
            selectednav.className = selectednav.className.replace(/\bms-core-listMenu-selected\b/, '');
        }
        var query = window.location.pathname.split('/').pop() + location.search
        var navElements = leftNavBar.getElementsByClassName("ms-core-listMenu-item");
        for (var i = 0; i < navElements.length; i++) {
            if (navElements[i].getAttribute("href").indexOf(query) != -1) {
                navElements[i].className = navElements[i].className + " ms-core-listMenu-selected";
                break;
            }
        }

    }
_spBodyOnLoadFunctionNames.push("fixLeftNavSelection");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.