胖在一方

出得厅堂入得厨房的胖子

导航

保存网页位置

Posted on 2006-09-12 17:37  胖在一方  阅读(348)  评论(0)    收藏  举报

一、增加脚本

 1 <script language="javascript">
 2         function  saveScrollPosition()
 3 
        {
 4             //
测试位置
 5             window.defaultStatus =
document.body.scrollTop ;
 6             var hid =document.getElementById('hidScrollPosition')

 7             if(hid != null)
 8 
            {
 9                 hid.value=
document.body.scrollTop ;
10 
            }        
11 
            
12 
        }
13 
        
14         function
 setScrollPosition()
15 
        {
16             var hid =document.getElementById('hidScrollPosition');

17             if (hid!=null)
18 
            {
19 
                
20                 if(parseInt(hid.value,10>0
 )  
21 
                {
22                     document.body.scrollTop =
 hid.value;
23 
                }
24 
            }
25 
        }
26         </script>

二、在 <Body> 中增加2个事件处理方法,
1<body MS_POSITIONING="GridLayout" onscroll="saveScrollPosition()" onload ="setScrollPosition()">

三、增加一个Hidden控件,以便页面PostBack后能保存 scrollTop的值
1<input type="hidden" id="hidScrollPosition" runat=server>

四、增加一个服务器控件,PostBack页面
1     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
2         Response.Write(String.Format("<script language=JavaScript>window.alert('{0}');</script>", Request("hidScrollPosition"
)))
3     End Sub

五、在页面上,添n多的东西,出现滚动条,自己测试吧