简体   繁体   English

使用Ajax jQuery localStorage跨浏览器

[英]Using Ajax jQuery localStorage cross-browser

I have done this Ajax jQuery function that saves the scroll position in a localStorage and it works fine on Chrome but it does not work on the other web browsers, what can I do to make it work on all platforms? 我已经完成了此Ajax jQuery函数,该函数将滚动位置保存在localStorage中,并且在Chrome上可以正常运行,但在其他Web浏览器上无法正常工作,我该怎么做才能使其在所有平台上都能正常工作?

JS: JS:

<script type="text/javascript">
            $.ajax({
            type: "GET",
            url: "AdminListUsers.aspx?column=Disabled&direc=False&a=chstat&z=+",
            success: function loadDoc() {
                $(window).unload(function () {
                    var scrollPosition = $("body").scrollTop();
                    localStorage.setItem("scrollPosition", scrollPosition);
                });
                if (localStorage.scrollPosition) {
                    $("body").scrollTop(localStorage.getItem("scrollPosition"));
                }
            }
        });
    </script>

C#: C#:

var toggleUrl = "AdminListUsers.aspx?column=" + (IsClicked.FirstOrDefault().Key ?? "Name") + "&direc=" + (IsClicked.FirstOrDefault().Value) + "&a=chstat&q=" + id.ToString() + "&d=" + disabled + "&z=" + Server.UrlEncode(txtSearchFor.Text);

        var hl = new HyperLink();
        hl.Text = status;
        hl.Style.Add(HtmlTextWriterStyle.Color, (disabled ? "red" : "green"));
        hl.NavigateUrl = toggleUrl;
        hl.Attributes.Add("onclick", "loadDoc();return true;");
        cell.Controls.Add(hl);
        tr.Cells.Add(cell);

The answer is to change the $("body").scrollTop(); 答案是更改$("body").scrollTop(); to $(window).scrollTop(); $(window).scrollTop();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM