How to go to a specific dataset page

Hi,
In my page (X) with a dataset, when user clicks a specific item, a new window (Y) opens. In this new window, there is a button ‘Go back’. When user click this button, he/she returns to Y, and I want to show the dataset PAGE when was on the window X beforehand.

What I do:

1- In X → When user press Go to specific item (page Y): I set session with dataset.getCurrentPageIndex()
2- In Y → I read session and store the pageIndex sent from X into a variable
3- In Y → When user press Go Back, I set session again from the variable I set in pevious step
4- Now I am in X back again but I don’t know how to set dataset pageIndex coming from Y ???

Can you let me know how can I set the dataset pageIndex to the specific number coming from page Y?

Thanks

There are already a good few tutorials for next and previous and back buttons.
https://support.wix.com/en/article/corvid-tutorial-creating-previous-and-next-buttons-for-a-dynamic-item-page-with-code
https://www.grampsworkbench.com/Examples/Back-Button
https://www.grampsworkbench.com/Examples/Dynamic-Page-Loop

As for using Wix Storage, you can read all about that in the api reference here.
https://www.wix.com/corvid/reference/wix-storage.html
https://www.wix.com/corvid/forum/community-discussion/solved-wix-storage-transferring-data-between-pages
https://www.vorbly.com/Vorbly-Code/WIX-CODE-PASSING-DATA-BETWEEN-PAGES

To pass data from page to lightbox or from lightbox to page see here for more.
https://www.wix.com/corvid/reference/wix-window.html#openLightbox
https://www.wix.com/corvid/reference/wix-window.lightbox.html#close

Finally, have a read of the api reference for get current page index and make sure that you put the dataset into your pages own onReady event if you want to get it as soon as possible.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentPageIndex

However that will only get the current page index and not take you to it, to do that you will need to use something like this.

location.href.split('/').pop();
//or
var urlsplit = location.href.split("/");
var scriptName = urlsplit.pop().split("?")[0].split("#")[0] || "index.php";

See here for more info.
wix-location-frontend - Velo API Reference - Wix.com
window.location.href and window.open () methods in JavaScript - Stack Overflow
Window.location.href () and Window.open () in JavaScript - Stack Overflow
Window: location property - Web APIs | MDN
JavaScript Window Location