MaintainScrollPositionOnPostback属性不适用于mozilla

时间:2012-03-07 18:34:25

标签: asp.net

MaintainScrollPositionOnPostback = true

它使用IE但不使用mozilla(版本9)

建议另一种保持与浏览器无关的滚动位置的方法。

thanxx

2 个答案:

答案 0 :(得分:11)

在这里找到答案:

http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx

在这里:

http://www.4guysfromrolla.com/articles/111704-1.aspx

让我知道它是否适合您!


修改

由于我只是有链接答案,我实际上只是粘贴代码片段,以防这些链接消失:

来自http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx

<script type="text/javascript">
    var xPos, yPos;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);
    function BeginRequestHandler(sender, args) {
        xPos = $get('scrollDiv').scrollLeft;
        yPos = $get('scrollDiv').scrollTop;
    }
    function EndRequestHandler(sender, args) {
        $get('scrollDiv').scrollLeft = xPos;
        $get('scrollDiv').scrollTop = yPos;
    }
</script>

来自:http://www.4guysfromrolla.com/articles/111704-1.aspx

<script language = "javascript">

    function sstchur_SmartScroller_GetCoords()
    {
        var scrollX, scrollY;

        if (document.all)
        {
            if (!document.documentElement.scrollLeft)
                scrollX = document.body.scrollLeft;
            else
                scrollX = document.documentElement.scrollLeft;

            if (!document.documentElement.scrollTop)
                scrollY = document.body.scrollTop;
            else
                scrollY = document.documentElement.scrollTop;
        }   
        else
        {
            scrollX = window.pageXOffset;
            scrollY = window.pageYOffset;
        }

        document.forms[formID].xCoordHolder.value = scrollX;
        document.forms[formID].yCoordHolder.value = scrollY;
    }

    function sstchur_SmartScroller_Scroll()
    {
        var x = document.forms[formID].xCoordHolder.value;
        var y = document.formsformID].yCoordHolder.value;
        window.scrollTo(x, y);
    }

    window.onload = sstchur_SmartScroller_Scroll;
    window.onscroll = sstchur_SmartScroller_GetCoords;
    window.onkeypress = sstchur_SmartScroller_GetCoords;
    window.onclick = sstchur_SmartScroller_GetCoords;

<script>

所有对这些答案都努力工作的人都很有信心。

答案 1 :(得分:0)

我刚刚在旧代码库上遇到了同样的问题。将 .NET Framework 从 3.5 更新到 4.7 为我清除了它。