我已经完成了这个Ajax jQuery函数,它可以在localStorage中保存滚动位置,并且它在Chrome上工作正常,但它不能在其他Web浏览器上运行,我该怎么做才能让它在所有平台上运行?
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#:
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);
答案 0 :(得分:0)
The answer is to change the $("body").scrollTop();
to $(window).scrollTop();