I would like to make a landing page with menu and anchor navigation per section.
I can’t found any topics in this community about anchors.
Hey,you can use the normal anchor behavior
- Put an id on the element you want to scroll to (like a title)
- Use it on the anchor of your link (#my-id)
URL https://link.com#anchor makes redirect with page reloading.
What wrong?
If you want to change in the same page, the best is to use the scrollTo js function
document.getElementById(“YOUR_ID”).scrollTo(0,0);
Can you replace document by wwLib.getFrontDocument()
This will be
wwLib.getFrontDocument().getElementById(“YOUR_ID”).scrollTo(0,0);
And be sure that the id exist
Thank you for your answers! This doesn’t work for me. The script is running but the action is not happening
That’s strange. Do you have any error on the Chrome devtool?
Is the id correct (double check with the editor)?
Are you trying to scroll to a modal?
hey @dorilama, thanks for the reply. Confirmed ID is correct. The element is not a modal.
It’s an expand component (collection item) in a collection list
It’s clearly not in the page when you execute the code.
The easiest thing you can try is adding a delay before the action.
I’ll play with this some more today and see what I can find.
If you happen to have a moment, @dorilama, this post is really what I’m trying to get done: Little help? Link and anchor to a static collection page - #2 by clncsports
Would greatly appreciate any point in the right direction!
In my experience, .scrollTo(x,y) doesn’t work in the editor but .scrollIntoView() works just fine.
document.getElementById(‘PUT YOUR ID HERE’).scrollIntoView();
Of course, you still need to set a unique ID on your TARGET destination.
Hope that helps.
From your other post I imagine you are trying to scroll to an element when changing page. If that is the case probably your problem is that the element does not exist yet in the page. You can try adding a delay but that’s not ideal.
Note: If you are copying and pasting the above Solution, note the tick marks used will not work. Use this instead:
document.getElementById('YourIDHere').scrollIntoView();
I was using anchor to navigate to certain sections in same page but it didn’t work for me.
So I created workflow of type custom javascript with a code:
wwLib.getFrontDocument().getElementById(“PUT YOUR ID HERE”).scrollIntoView();
you still need to set a unique ID on your TARGET destination Like:
wwLib.getFrontDocument().getElementById(“documents”).scrollIntoView();
Hope this will help