A "Back Button" that calls upon browser history and scroll position.

I’ve seen @yisrael-wix helpful example documentation for a back button. This seems to work, although I’ve not tested it on various browsers.
The function that is missing however is, returning the user to the page position of the previously viewed page.
Any advice welcome.

Yisrael’s shared code is below, where "#button” is the button name.

import {session} from 'wix-storage';
import wixLocation from 'wix-location';

let previousPageURL;

$w.onReady(function () {

    previousPageURL = session.getItem("page");
    console.log(previousPageURL);
    session.setItem("page", wixLocation.url);
    $w("#button").link = previousPageURL;
    $w("#button").target = "_self";
});

What do you see when you look onto the code?
What you do understand and what you don’t ?

To be more precise…

Yisrael’s shared code is below, where " #button ” is the button name.
It’s the BUTTON-ID , not the NAME!

What does the shown code, provided by Yisrael do ?
Does it loads always the last visited page-url and puts it to a button as a link, to be opened in the same window?

So how is called your button, or better asked → WHAT IS THE ID OF YOUR BACK/PREVIOUS-BUTTON?

Just replace your the button-ID inside CODE, with the BUTTON-ID of your own BUTTON.

Sorry, but you have not understood my query.
The code above works for me perfectly fine, I posted it there as an example of where I’m at. I think that was quite clear.
I would like to know if there’s a way to go back to a page to the same scroll position. For example, if I was scrolled halfway down the previous page that’s where I want to go back to. Like the browser back functionality.

Oh, yes now i see what you were looking for.

I think yes → there is a way of how to do that.
Take a look onto the following commands and try to create your own function, which will do the trick…
https://www.wix.com/velo/reference/wix-window/scrollby
https://www.wix.com/velo/reference/$w/mouseevent/pagex
https://www.wix.com/velo/reference/$w/mouseevent/pagex
https://www.wix.com/velo/reference/$w/mouseevent/pagey
https://www.wix.com/velo/reference/wix-window/getboundingrect
https://www.wix.com/velo/reference/wix-window/scrollto

Also have a look onto this one…
https://www.wix.com/velo/forum/tips-tutorials-examples/tracking-mouse-move-with-velo-code