For primary navigation on site:
http://dangelmayer.com/index_new.php, when clicking into a sub-page from the primary navigation, I want only the selected main category to persist in red until user clicks into a different main category, then that different main category only turns red.
- <script>
- $(document).ready(function() {
- $("#pnav a").click(function(e) {
- e.preventDefault(); //force link to go via javascript handling cookies first
-
- //remove existing cookie on host computer
- if ($.cookie('css') != null ) {
- alert('Removing Cookie on click = '+$.cookie('css'));
- $.cookie("css", null, {path: '/'});
- }
- // Setting value for cookie and redirecting to clicked link
- var linkto = $(this).attr('href');
- var target = $(this).closest('li.primary').find('img.grey').attr("id");
- $.cookie('css', target, {path: '/'});
- alert('Setting Cookie on click = '+$.cookie('css'));
- alert('Going to page = '+linkto);
- window.location = linkto;
- //}
- });
- // Special case, if home page is clicked, remove red image in prim. nav.
- var locatepath = $(location).attr('pathname');
- if (locatepath == '/index_new.php') {
- $.cookie("css", null, {path: '/'});
- alert('Removing Cookie on click = '+$.cookie('css'));
- }
- //Finally, read cookie and change selected primary navigation to red
- if($.cookie('css')) {
- $('#'+$.cookie('css')).css('display', 'none');
- alert('Retrieving Cookie for Primary navigation = '+$.cookie('css'));
- }
- });
- </script>
and an example section of the primary navigation is below. Clicking on any link here will create a cookie with the value "
daadvg".
- <nav id="topnav">
- <ul id="navmenu" class="sf-menu">
- <li id="pnav" class="primary daadv">
- <a class="menusd homex" href="http://www.dangelmayer.com/index_new.php" title="The Dangelmayer Advantage" target="_self" onmouseover="this.title='';" style="padding-top:10px;"><span class="primnavtxt">The Dangelmayer<br />Advantage</span></a>
- <img src="/images/new/nav_prim_grey.png" style="width:136px;" class="grey" id="daadvg" alt="" />
- <img src="/images/new/nav_prim_hover_red.png" style="width:136px;" class="red" alt="" />
- <ul>
- <li><a href="http://dangelmayer.com/dream-team.php" title="Dangelmayer Associates Dream Team" rel="_self" onmouseover="this.title='';">Dream Team <span class="sf-sub-indicator"> »</span></a>
- <ul>
- <li><a href="http://dangelmayer.com/dream-team.php" title="Dangelmayer Associates Dream Team" rel="_self" onmouseover="this.title='';">Team Biographies</a></li>
- <li><a href="http://dangelmayer.com/achievements.php" title="Dangelmayer Associates Achievements" rel="_self" onmouseover="this.title='';">Team Achievements</a></li>
- </ul>
- </li>
- <li><a href="http://dangelmayer.com/mission-statement.php" title="Dangelmayer Associates philosophy/approach (reputation/no conflict of interest)" rel="_self" onmouseover="this.title='';">Philosophy</a></li>
- <li><a href="http://dangelmayer.com/customer-base.php" title="Dangelmayer Associates Customer Base (long-term happy customers)" rel="_self" onmouseover="this.title='';">Customer Base</a></li>
- <li><a href="http://dangelmayer.com/company-locations.php" title="Dangelmayer Associates Worldwide Coverage" rel="_self" onmouseover="this.title='';">Worldwide Coverage</a></li>
- </ul>
- </li>
- </ul>
- </nav>
Issue:
Should work like:
Clicking on a link will delete the old cookie (redundant, but done because of this issue), (only one cookie name exist), create a new cookie and then redirect user to their requested new page, read the new cookie value, then set the selected primary navigation to red based on that value.
But get this strange behavior:
This works sometimes, but others, it pulls values of this cookie that are 2 or 3 deleted cookies prior. I am not sure how jQuery stores the cookie value (in browser session?), but somehow it is not really deleting or reading the correct cookie (appears to be a random problem).
Right now, for diagnostics, I have all the JavaScript alerts on so you can see the stages of cookie handling.
Any help would greatly be appreciated.
Thank you!