Check scroll saver

Do you have idea why the scroll saver doesn’t work. After autopost back the application come back to TOP. The application should save the current scroll, and in some cases it does not work correcly and i don’t know why is that, and i don’t know what, as i said a few month early it work, but as Browser is update , something is wrong.
After autopost back the application come back to TOP. The application should save the current scroll

// scrollsaver.js

(function () {
    function loadScroll() {
        var cookieList = document.cookie.split(';');
        for (var i = 0; i < cookieList.length; i++) {
            var cookieParts = cookieList[i].split('=');
            if (cookieParts[0] == 'scrollPosition') {
                var values = unescape(cookieParts[1]).split('/');
                for (var j = 0; j < values.length; j++) {
                    var currentValue = values[j].split(',');
                    try {
                        if (currentValue[0] == 'window') {
                            window.scrollTo(currentValue[1], currentValue[2]);
                        } else if (currentValue[0]) {
                            var elm = document.getElementById(currentValue[0]);
                            elm.scrollLeft = currentValue[1];
                            elm.scrollTop = currentValue[2];
                        }
                    } catch (ex) { }
                }
                return;
            }
        }
    }
    function saveScroll() {
        var s = 'scrollPosition=';
        var wl, wt;
        if (window.pageXOffset !== undefined) {
            wl = window.pageXOffset;
            wt = window.pageYOffset;
        } else if (document.documentElement && document.documentElement.scrollLeft !== undefined) {
            wl = document.documentElement.scrollLeft;
            wt = document.documentElement.scrollTop;
        } else {
            wl = document.body.scrollLeft;
            wt = document.body.scrollTop;
        }
        if (wl || wt) {
            s += 'window,' + wl + ',' + wt + '/';
        }
        var elements = (document.all) ? document.all : document.getElementsByTagName('*');
        for (var i = 0; i < elements.length; i++) {
            var e = elements[i];
            if (e.id && (e.scrollLeft || e.scrollTop)) {
                s += e.id + ',' + e.scrollLeft + ',' + e.scrollTop + '/';
            }
        }
        document.cookie = s + ';';
    }
    var addEvent, eventPrefix;
    if (window.attachEvent) {
        addEvent = window.attachEvent;
        eventPrefix = 'on';
    } else {
        addEvent = window.addEventListener;
        eventPrefix = '';
    }
    addEvent(eventPrefix + 'load', function () {
        loadScroll();
        if (typeof Sys != 'undefined' && typeof Sys.WebForms != 'undefined') {
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(loadScroll);
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(saveScroll);
        }
    }, false);
    addEvent(eventPrefix + 'unload', saveScroll, false);
})();

Hi hkelzentarja, welcome to the forums!

I’m not knowledgeable enough to answer your question. :slight_smile:

But you might get a quicker response if you mention in what browser(s) you tested the script and if you have an earlier version that worked, or if there are other details you think can help the next member to see what could be the cause it doesn’t work or get executed now.

My first guess would be that when you updated the browser the cookie settings were changed. Did you check to see what those settings are?

Knowing at least something, even if not clearly understood, would be a big help. If you open the browsers dev tools console and visit the page are there any error messages?

i use firefox

No i think it has something realated with the code, i had the same problem before, but this time i am not finding what is wrong

I guessed that, good that you confirmed. :slight_smile:

Even if you don’t think it matters, please tell what was wrong with the same problem before. Was it too caused by a Firefox update?

In the dev tools (Tools-Webdeveloper-Web Console) you can check the log for errors. Did that give any clue?


Please read the tips in the FAQ on how to get the best help:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.