“maintainScrollPositionOnPostBack=”true“ ” does not work with google chrome

倖福魔咒の 提交于 2019-11-28 03:40:21

问题


  1. Web.config Level => pages maintainScrollPositionOnPostBack="true" />

  2. Page Level => <%@ Page MaintainScrollPositionOnPostback="true" %>

  3. Code Level => Page.MaintainScrollPositionOnPostBack = true;

  4. Browser Level => browser id="Chrome" parentID="Safari1Plus"> capabilities> capability name="supportsMaintainScrollPositionOnPostback" value="true" /> capabilities> browser>

Any of the 4 ways mentioned above did not work with google chrome. It is working fine with firefox. Kindly provide any solution .


回答1:


You can add this snippet to your ASP.NET Page/MasterPage (jQuery required):

<asp:HiddenField runat="server" ID="hfPosition" Value="" />
<script type="text/javascript">
    $(function () {
        var f = $("#<%=hfPosition.ClientID%>");
        window.onload = function () {
            var position = parseInt(f.val());
            if (!isNaN(position)) {
                $(window).scrollTop(position);
            }
        };
        window.onscroll = function () {
            var position = $(window).scrollTop();
            f.val(position);
        };
    });
</script>



回答2:


I also faced same problem. I found one Javascript solution here.

<script type = "text/javascript">
window.onload = function () {
    var scrollY = parseInt('<%=Request.Form["scrollY"] %>');             
    if (!isNaN(scrollY)) {
        window.scrollTo(0, scrollY);
    }
};
window.onscroll = function () {
    var scrollY = document.body.scrollTop;
    if (scrollY == 0) {
        if (window.pageYOffset) {
            scrollY = window.pageYOffset;
        }
        else {
            scrollY = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }
    }
    if (scrollY > 0) {
        var input = document.getElementById("scrollY");
        if (input == null) {
            input = document.createElement("input");
            input.setAttribute("type", "hidden");
            input.setAttribute("id", "scrollY");
            input.setAttribute("name", "scrollY");
            document.forms[0].appendChild(input);
        }
        input.value = scrollY;
    }
};

I hope this would help you.



来源:https://stackoverflow.com/questions/25811275/maintainscrollpositiononpostback-true-does-not-work-with-google-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!