window.location.pathname not working after publish? RRS feed

  • Question

  • User1224379429 posted


    I am using the below code to highlight the current page. Its working fine when I run from Visual Studio but its not working after publish.

    jQuery.each(jQuery('.nav').find('li'), function () {
                jQuery(this).find('a').attr('href') == window.location.pathname);
        jQuery('.active').closest('ul').css('display', 'block');

    following is my path after publish 


    Sunday, September 25, 2016 7:19 AM

All replies

  • User475983607 posted

    First, open your developer tools (F12) and make sure you are not getting 404 errors loading script files.  This a common issue where the script files references are not relative to the application root.

    Second, use developer tools to debug your code.  Are there any script errors? If so, what are the errors.

    Sunday, September 25, 2016 2:09 PM
  • User-574805748 posted


       let us have your nav markup on the published environment 

    Monday, September 26, 2016 3:59 PM
  • User-1355486065 posted

    It must be something to do with the 

    jQuery(this).find('a').attr('href') == window.location.pathname

    check your console and find the pathname and check it matches with your href or not.

    Monday, October 3, 2016 5:44 AM
  • User-574805748 posted


        do a look on the pathname on debug sometimes it's recognized as '/' root location and the href is the uri http://www.xxx.com

        i propose you publish on IIS and debug it before sending to deploy environment  

    Monday, October 3, 2016 7:06 AM