Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

asp.net - MaintainScrollPositionOnPostback property doesn't works with mozilla

MaintainScrollPositionOnPostback = true

its working with IE but not with mozilla(version 9)

suggest another way of maintaining scroll position that is browser independent..

thanxx

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found the answer here:

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

and here:

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

Let me know if it works out for you!


EDIT

Since I just had link answers I am actually just going to paste the code snippets here in case those links disappear:

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

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

All the credit to the guys that worked hard on these answers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...