How to make page not go to 0 when redirected

Viewed 50

I have a page where there are at least 20 rows in a table, in one of the columns there is a link, I click that link and then it sets the vertical scroll to 0, although I have made a cookie which gets the scroll amount each time you scroll.

When I refresh my page, the scroll stays where it was, because of my cookie I set, but when I click the link which does something with my database and then redirect back, the scroll is set back to 0.

This is my code at the moment:

document.addEventListener("scroll", function() {
    {{!session['scrolledY']}} = window.scrollY;
    console.log({{session['scrolledY']}});
});

And then above this I have:

window.scrollTo({{session['scrolledY']}}, 0);

And this works when I refresh my page, but when I go to a different link it doesn't keep me where I am.

The {{...}} is an escaping method for the python web library I use, and the session is the cookie library

Edit: I just realised when refreshing, it automatically sets the scroll where you last were, so my code isnt even doing anything really.

Edit: Again, I just realised, because for some reason I didn't look at the console I didn't see an error had been thrown, it turns out, that the {{session['scrolledY']}} isn't a variable, which I knew might happen,but I have no knowledge on how to escape some code while being able to assign a value that isnt a python value.

0 Answers
Related