1. PROMO Subscribe our All Access Pass @ 75% OFF & access all our 16+ premium Divi extensions: Divi Block Pro, Carousel Toolkit, etc.LEARN MORE
Dismiss Notice
NEW Divi.Help Pro Carousel AI Toolkit - Magically turn your Divi design into carousel, simply by using our online toolkit. No plugins needed. Now it works with Divi 5 as well!Try our carousel AI toolkit
BEST Divi Block - A revolutionary drag & drop tool to easily mix & match 960+ premade blocks (Light & Dark) to kick start your Divi site design. Special module designs are included as well. Also newly added AI generator & color. Now it works with Divi 5 as well!
Learn More About Divi BlockFree Version ~ 340+ Free Blocks

Prevent Anchor Links from Showing in URL Bar on Click

Discussion in 'Free Divi Community Forum' started by GideonS, Feb 18, 2023.

  1. GideonS

    GideonS New Member

    Hello, I am using a Divi Booster plugin called Show/Hide Module which allows me to show or hide specific sections of my page on click. Rather than using it as buttons though, I am using the code below to let me use a link that navigates to the button then clicks it. However, when I use that anchor link, it shows up in the url bar. Other anchor links on my site aren't doing that. Is there some code I can add that will prevent that or is there some code I need to remove or edit below? I appreciate any help!

    <script>
    /* Open a Divi Show / Hide Module when Linking to the Page */
    jQuery(function($) {

    // Click button if id set in url hash
    setTimeout(
    function(){
    var button_id = location.hash.substring(1);
    if (button_id !== '') {
    $('#'+button_id+'.et_pb_db_show_hide_button .et_pb_button').trigger('click');
    }
    },
    1000
    );

    // Handle same page links
    $('a[href*="#"]').each(
    function() {
    var $link = $(this);
    var link_url = $(this).attr('href');
    var link_hash = link_url.substring(link_url.indexOf("#") + 1);
    if (link_hash.length > 0) {
    var $button = $('.et_pb_db_show_hide_button#'+link_hash);
    if ($button.length) {
    $link.unbind('click');
    $link.on('click', function() {
    et_pb_smooth_scroll($button, false, 800);
    $button.not('.dshb-active-button').find('.et_pb_button').click();
    });
    }
    }
    }
    );
    });
    </script>
     
    1. PRO MEMBER PERKS Custom Color Scheme + Premade Layouts - A perfect combination to boost productivity:Try Now
  2. Divi.Help

    Divi.Help Administrator
    Staff Member

    There's a smooth scroll jQuery in it. You may try to remove it: et_pb_smooth_scroll($button, false, 800);

    If still not working, then you may change the below:

    $link.on('click', function() {
    et_pb_smooth_scroll($button, false, 800);


    into:

    $link.on('click', function(e) {
    e.preventDefault();
     
    GideonS likes this.
  3. GideonS

    GideonS New Member

    The second solution worked perfectly! Thanks for your help. Only thing, when I access the site in Google Chrome, it behaves strangely when I click on the photos with the anchor link (that click the show/hide module and switch out my section content). It seems to work with the first few clicks, then starts navigating to weird places in the site on the rest of the clicks. But it works great in Safari. I'm assuming the issue with Chrome is unrelated to the code, but I'll continue to investigate it. (The website is www.ruthretreat.com, when you click the different speaker photos, it is set to use the hidden show/hide module to toggle the content)

    Anyhow, thank you for your assistance!
     
    1. PRO MEMBER PERKS Beautifully crafted custom colored 'Freelancer' Divi layout for all Pro members:View Demo