Code does not function if you go to page URL but does if you click on link connected to page.

I have code on a page that’s name has changed but the URL remains the same. The code only works if you get to the page from a link attached to by page(see image), I have a pinned element linked this way as well as the menu. If you refresh the page or connect from putting the URL in the browser the code does not work. Any ideas on how to fix this fast?

export function button27_click ( event ) {
$w ( ‘#columnStrip23’ ). expand ();
$w ( “#anchor1” ). scrollTo ()
. then (() => {
console . log ( “Done with scroll” );
});
}
export function button31_click ( event ) {
$w ( ‘#columnStrip23’ ). expand ();
$w ( “#anchor1” ). scrollTo ()
. then (() => {
console . log ( “Done with scroll” );
});
}

// Hides the element when the page loads
$w ( “#box30” ). hide ();

The hidden object code works but not the button clicks. Here is the link; https://www.bighornriveralliance.org/year-end-giving

The last line you posted has to be in $w.onReady:

$w.onReady(() => {
    $w("#box30").hide();
});

That hide element function is the only code that works either way you connect to the page. It hides the pinned element that is connected to the page.

@melissa44384 But as I said you should put it in $w.onReady so it won’t break the code.

@jonatandor35 Do you mean instead of the export function?

@melissa44384 No.
Just like that:

$w.onReady(() => {
$w("#box30").hide();
});
export function button27_click(event) {
    $w('#columnStrip23').expand();
    $w("#anchor1").scrollTo()
        .then(() => {
            console.log("Done with scroll");
        });
}
export function button31_click(event) {
    $w('#columnStrip23').expand();
    $w("#anchor1").scrollTo()
        .then(() => {
            console.log("Done with scroll");
        });
}

@jonatandor35 I just got what you mean!!

1 Like

@jonatandor35 Thank you so much!!!

You’re welcome. But pay attention, it looks like box30 doesn’t exist on your mobile mode, so this code might break there. You should either add this element to the mobile mode, or run the code on desktop only.