vb.net “maintainScrollPositionOnPostBack="true“" 不适用于谷歌浏览器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25811275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:11:45  来源:igfitidea点击:

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

asp.netvb.netcross-browsermaster-pageswebusercontrols

提问by Pranav Kumar

  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>

  1. Web.config Level => pages维持ScrollPositionOnPostBack="true" />

  2. 页面级别 => <%@ PageMaintainScrollPositionOnPostback="true" %>

  3. 代码级别 => Page.MaintainScrollPositionOnPostBack = true;

  4. 浏览器级别 => 浏览器 id="Chrome" parentID="Safari1Plus"> 能力> 能力名称="supportsMaintainScrollPositionOnPostback" value="true" /> 能力> 浏览器>

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

上面提到的 4 种方式中的任何一种都不适用于 google chrome。它在 Firefox 中运行良好。请提供任何解决方案。

回答by Darkseal

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

您可以将此代码段添加到您的 ASP.NET 页面/MasterPage(需要 jQuery):

<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>

回答by ShaileshDev

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

我也面临同样的问题。我在这里找到了一个 Javascript 解决方案。

<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.

我希望这会帮助你。