# Why does scrolling to an anchor fail after login

**URL:** <https://forum.wixstudio.com/t/why-does-scrolling-to-an-anchor-fail-after-login/77802>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [April 22, 2026, 2:35am UTC](https://forum.wixstudio.com/t/why-does-scrolling-to-an-anchor-fail-after-login/77802 "2026-04-22T02:35:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![user858](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/user858/32/80745_2.png) [@user858](https://forum.wixstudio.com/u/user858)\
**Post date:** [April 22, 2026, 2:35am UTC](https://forum.wixstudio.com/t/why-does-scrolling-to-an-anchor-fail-after-login/77802/1 "2026-04-22T02:35:32Z")

</div>

Interesting that this only works sometimes.

If I log off (the page is “members only”) then go to the URL with included anchor, I’m prompted to log in. That’s good.

When I complete the login I go to the correct page but I do NOT scroll to the anchor until I either refresh the page or hit enter in the address bar of the browser. That’s bad - defeats the purpose of the anchor in the URL.

Anybody have a clue why that is? What I can do about it?

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [April 22, 2026, 12:47pm UTC](https://forum.wixstudio.com/t/why-does-scrolling-to-an-anchor-fail-after-login/77802/2 "2026-04-22T12:47:41Z")

</div>

It’s simply because logging in doesn’t force a page refresh - and this method only works on page load.

---

<div class="post-metadata">

**Author:** ![user858](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/user858/32/80745_2.png) [@user858](https://forum.wixstudio.com/u/user858)\
**Post date:** [April 22, 2026, 11:26pm UTC](https://forum.wixstudio.com/t/why-does-scrolling-to-an-anchor-fail-after-login/77802/3 "2026-04-22T23:26:13Z")

</div>

Thanks for the explanation.

Is there a viable alternative?

The help documents say that I should click on an anchor, choose settings, and then choose “anchor URL” to get a direct URL for that anchor but the last part is not an option presented in my web site editor - hence this attempt.

Even if the option described in the help (see below) did work, would the log in process stop processing of the “scroll to anchor” activity?

Help screenshot

 ![image](https://us1.discourse-cdn.com/wix/original/3X/9/6/96fb641b1fcec4352c7967587a5553d8ea1f8264.png)

My site’s screen shot of the same process.

 ![image](https://us1.discourse-cdn.com/wix/original/3X/8/c/8c128555aa6986b3a0706a076af0697c1392cd1e.png)

The vital part is missing.

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [April 23, 2026, 12:39pm UTC](https://forum.wixstudio.com/t/why-does-scrolling-to-an-anchor-fail-after-login/77802/4 "2026-04-23T12:39:10Z")

</div>

> [@user858](#):
>
> Even if the option described in the help (see below) did work, would the log in process stop processing of the “scroll to anchor” activity?

Correct - even with the URL from the editor, it wouldn’t work after login without a small amount of code.

When you’ve enabled Dev Mode (at the top of the editor), select the anchor and change it’s ID to something that you want (e.g. memberStories).

You’ll use this ID in your URL - `https://mysite.com/#memberStories`

 ![Screenshot 2026-04-23 at 13.37.27](https://us1.discourse-cdn.com/wix/original/3X/7/5/7568094e661bb74fb60b039da53e6d21c20878d2.png)

Then you’ll need some code like this in the `masterPage.js` file, which basically runs on login, checks if the URL has the hash, and then scrolls to that element.

```javascript
import * as wixSiteLocation from '@wix/site-location';
import { onLogin } from "@wix/authentication";

$w.onReady(function () {
    onLogin(async () => {
        console.log("Member logged in");

        // 1. Get the full URL string
        const fullUrl = await wixSiteLocation.location.url();

        // 2. Check if the URL contains a '#'
        if (fullUrl.includes('#')) {
            // Split the string at '#' and take the part after it
            const targetId = fullUrl.split('#')[1];
            const targetElement = $w(`#${targetId}`);

            if (targetElement) {
                targetElement.scrollTo()
                    .then(() => {
                        console.log(`Scrolled to ${targetId}`);
                    })
                    .catch((err) => {
                        console.error("Scroll failed", err);
                    });
            } else {
                console.warn(`No element found with ID: ${targetId}`);
            }
        }
    });
});

```

---

<div class="post-metadata">

**Author:** ![user858](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/user858/32/80745_2.png) [@user858](https://forum.wixstudio.com/u/user858)\
**Post date:** [April 26, 2026, 1:11am UTC](https://forum.wixstudio.com/t/why-does-scrolling-to-an-anchor-fail-after-login/77802/5 "2026-04-26T01:11:33Z")

</div>

Not winning with this one. I can see that code executed but none of the “console.log” statements produce an entry in the wix log (I’m guessing they’re popping up on a server somewhere rather than in my client?").

I’ve tried using both the anchor’s name and the “comp-mmk455wg” tag extracted using the “inspect” option in Edge to view the code. I can manually enter the comp version and scroll to the page but, while the code executes, it doesn’t trigger a scroll-to-anchor.

Baffled!

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [April 27, 2026, 2:17pm UTC](https://forum.wixstudio.com/t/why-does-scrolling-to-an-anchor-fail-after-login/77802/6 "2026-04-27T14:17:23Z")

</div>

For the code above to work, you need to use the ID set, not from the live site.

In the example above, you can see the screenshot with the anchor selected. Below that, there’s “Properties & Events” in the code panel. Where the ID is `#anchor1` - that’s the ID you need to use
