Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1234278
    benefacere
    Participant

    Hi,

    I’m creating a multi page site with some anchor links menu toward homepage sections, and other links menu toward “independant pages”.

    See here : http://pyrum.bene-facere.fr/
    Menu item 1 : link toward section http://pyrum.bene-facere.fr/#recycling
    Menu item 2, 3, 4 : link to sections of homepage
    Menu item 5 : independant page
    Menu item 6 : popup

    On “other independant page than homepage” (like http://pyrum.bene-facere.fr/press/), the anchor menu links (menu item 1,2,3,4) works but the top menu is positionnating a bit lower on the homepage whereas it’s perfect when i click on a anchor menu link on the homepage itself.

    Can you help ?

    Thanks !

    #1234443
    Rue Nel
    Moderator

    Hello There,

    Thanks for writing in! I can confirm that the placement of the section is different when you are clicking from an independent page. To resolve this, please add the following JS code in the customizer, Appearance > Customize > Custom > Javascript

    jQuery( function( $ ) {
     var hash = window.location.href.split('#')[1];
     if ( $('.page').length > 0 && hash !== undefined ) {
      $( document ).ready( function() {
        $( '.x-navbar a[href$="#'+ hash +'"]').trigger('click');
      });
     }
    });

    We would loved to know if this has work for you. Thank you.

    #1234469
    benefacere
    Participant

    Thanks for the fast answer.

    I have integrated your (very logical !) code and the “click” is well triggered on click back to the homepage ; but i don’t see any difference yet…

    Any idea ?

    #1234554
    Lely
    Moderator

    Hi There,

    Please try updating the code to this:

    jQuery( function( $ ) {
     var hash = window.location.href.split('#')[1];
     if ( $('.page').length > 0 && hash !== undefined ) {
      $( document ).ready( function() {
        $( '.x-navbar a[href$="#'+ hash +'"]').trigger('click');
      });
     }
    });  

    Hope this helps.

    #1234720
    benefacere
    Participant

    Seems to be the exactly same code

    #1235102
    Nabeel A
    Moderator

    Hi there,

    I’ve checked your page and there is a JavaScript error on the page Uncaught TypeError: event.preventDefault is not a function Please navigate to your Appearance > Customize > Custom > Edit Global Javascript and remove this line of code:

    event.preventDefault();

    from this code:

    jQuery( function( $ ) {
     var hash = window.location.href.split('#')[1];
     if ( $('.page').length > 0 && hash !== undefined ) {
      $( document ).ready( function(event) {
        event.preventDefault();    
        $( '.x-navbar a[href$="#'+ hash +'"]').trigger('click');
      });
     }
    });

    Let us know how this goes!

  • <script> jQuery(function($){ $("#no-reply-1234278 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>