How do you remember scroll position using JS in a mobile (android) app

Viewed 56

I'm making a basic mobile app using HTML, and part of it is remembering the last position the user was on so when they reopen the app it goes back to the same position. I'm using this script, and it works properly on a browser, but not when you close an app and restart it.

I'm not very familiar with mobile apps, so I don't know how to fix it, appreciate your help.

Here's the script I use.

<script>
        function refreshPage() {
            var page_y = document.getElementsByTagName("body")[0].scrollTop;
            window.location.href = window.location.href.split('?')[0] + '?page_y=' + page_y;
        }
        window.onload = function() {
            setTimeout(refreshPage, 35000);
            if ( window.location.href.indexOf('page_y') != -1 ) {
                var match = window.location.href.split('?')[1].split("&")[0].split("=");
                window.scrollTo(0, match[1]);
            }
        }
    </script>
0 Answers
Related