页面刷新滚动条位置不变
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了页面刷新滚动条位置不变相关的知识,希望对你有一定的参考价值。
今天因为这个问题困扰了很久网上的例子都尝试没效果,后来发现一点原来是内容最外层没有div的原因
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SpotChkDetail.aspx.cs" Inherits="Topevery.DUM.Web.Observer.SpotChkDetail" %> 2 3 <script runat="server"> 4 protected override bool HeaderScriptFilter(Topevery.Framework.Web.Configuration.Script val) 5 { 6 switch (val.Key) 7 { 8 case "ajaxpro2.prototype": 9 case "ajaxpro2.core": 10 case "ajaxpro2.converter": 11 case "ajaxpro2.onloading": 12 case "ajaxpro2.assembly.AjaxFunction": 13 case "my97": 14 case "image": 15 case "jquery.pagination": 16 case "jquery.jqGrid.locale": 17 case "jquery.jqGrid": 18 case "jquery-load-image": 19 case "jquery.validationEngine": 20 case "jquery.validationEngine-zh": 21 case "WeiBo": 22 case "jquery.mousewheel": 23 case "jquery.iviewer": 24 case "jquery.gallery.singer": 25 return true; 26 default: 27 return base.HeaderScriptFilter(val); 28 } 29 } 30 31 protected override bool HeaderStyleFilter(Topevery.Framework.Web.Configuration.Style val) 32 { 33 switch (val.Key) 34 { 35 case "jqgrid": 36 case "jqgrid-grey": 37 case "validationEngine": 38 return true; 39 default: 40 return base.HeaderStyleFilter(val); 41 } 42 } 43 </script> 44 <!DOCTYPE html> 45 46 <html xmlns="http://www.w3.org/1999/xhtml"> 47 <head runat="server"> 48 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 49 <title></title> 50 </head> 51 <body id="bbdy"> 52 <form id="form1" runat="server"> 53 <div> 54 <div class="TUI-layout-north"> 55 <div class="TUI-title"> 56 <span class="TUI-ico ico-note"></span><strong>抽查</strong> 57 </div> 58 <div class="" style="float: right; margin-top: -30px; z-index: 99999; position: relative;"> 59 <object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0"> 60 </object> 61 <input type="button" class="TUI-button" value="打 印" onclick="document.all.WebBrowser.ExecWB(6, 1)" id="Button2" /> 62 <input type="button" class="TUI-button" value="打印预览" onclick="document.all.WebBrowser.ExecWB(7, 1)" /> 63 </div> 64 65 66 67 <div class="TUI-alert"> 68 <span class="ml10px">抽查时间:<asp:Label ID="lbBeginDate" runat="server" Text="Label"></asp:Label> 69 失效时间:<asp:Label ID="lbEndDate" runat="server" Text="Label"></asp:Label> 70 消息内容:<asp:Label ID="lbContent" runat="server" Text="Label"></asp:Label></span> 71 <div style="display: none"> 72 <asp:Button ID="btnRef" runat="server" OnClick="btnRef_Click" Text="刷新" /> 73 </div> 74 </div> 75 </div> 76 <div class="TUI-layout-center"> 77 <div class="TUI-content TUI-h100 TUI-of-auto TUI-align-center"> 78 <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound"> 79 <%--OnItemCommand="Repeater1_ItemCommand"--%> 80 <HeaderTemplate> 81 <table class="TUI-grid-list w100" id="observers"> 82 <tr> 83 <th style="width: 150px">巡查员头像 84 </th> 85 <th style="width: 80px">姓 名 86 </th> 87 <th style="width: 120px">是否超时 88 </th> 89 <%--<th style="width: 110px">城管通号码 90 </th> 91 <th style="width: 110px">城管通版本 92 </th>--%> 93 <th style="width: 100px">消息状态 94 </th> 95 <th style="width: 100px">审核状态 96 </th> 97 <th style="width:150px">审核 98 </th> 99 </tr> 100 </HeaderTemplate> 101 <ItemTemplate> 102 <tr class="people_title_td"> 103 <td rowspan="2" valign="middle" style="width: 110px"> 104 <img id="img_observer_poto" runat="server" height="135" style="border: 1px solid #bababa;" width="100" /> 105 </td> 106 <td style="width: 60px"> 107 <%# Eval("c_name")%> 108 <asp:HiddenField ID="hfObId" runat="server" Value=‘<%# Eval("c_ob_id") %>‘ /> 109 <asp:HiddenField ID="hfId" runat="server" Value=‘<%# Eval("c_id") %>‘ /> 110 </td> 111 <td style="width: 100px"> 112 <%# Eval("c_is_over_time")%> 113 </td> 114 <%--<td style="width: 110px"> 115 <%# Eval("c_pda_number")%> 116 </td> 117 <td style="width: 110px"> 118 <%# Eval("c_pda_version")%> 119 </td>--%> 120 <td style="width: 90px"> 121 <%# Eval("notify_state")%> 122 </td> 123 <td style="width: 90px"> 124 <%# Eval("eligible_state")%> 125 </td> 126 <td style="width:150px;"> 127 <div style="display:<%# Eval("c_is_eligible").ToString() !="0"?"none":"" %>"> 128 <%--<asp:LinkButton ID="LinkButton1" runat="server" CommandName="lnk_poto" CommandArgument=‘<%# Eval("c_id") %>‘>重摄</asp:LinkButton> 129 <asp:LinkButton ID="LinkButton2" runat="server" CommandName="lnk_ok" CommandArgument=‘<%# Eval("c_id") %>‘>合格</asp:LinkButton> 130 <asp:LinkButton ID="LinkButton3" runat="server" CommandName="lnk_no" CommandArgument=‘<%# Eval("c_id") %>‘>不合格</asp:LinkButton>--%> 131 132 <a href=‘#‘ onclick=‘review(<%# Eval("c_id") %>,0,"重摄")‘ class=‘TUI-toolbar-btn‘><span></span>重摄</a> 133 <a href=‘#‘ id="qualified" onclick=‘review(<%# Eval("c_id") %>,1,"合格")‘ class=‘TUI-toolbar-btn‘><span></span>合格</a> 134 <a href=‘#‘ id="Unqualified" onclick=‘review(<%# Eval("c_id") %>,2,"不合格")‘ class=‘TUI-toolbar-btn‘><span></span>不合格</a> 135 136 </div> 137 </td> 138 </tr> 139 <tr class="alt_tr2"> 140 <td colspan="5" style="height: 160px; text-align: left"> 141 <table class="choucha-table"> 142 <tr> 143 <asp:Repeater ID="rptImg" runat="server"> 144 <ItemTemplate> 145 <td> 146 <div class="div_img TUI-notelist-container TUI-gallery choucha-img"> 147 <div id=‘imge‘+‘<%#Eval("FileId") %>‘> 148 <div class="TUI-gallery-content TUI-gallery-img"> 149 <a title=‘点击放大‘ href="javascript:void(0)" 150 sourceSrc=‘<%#Eval("Imageurl") %>‘ largeSrc=‘<%#Eval("Imageurl") %>‘><img src=‘<%#Eval("Imagethumbil") %>‘ /><span><%#Eval("Summary") %></span></a> 151 </div> 152 </div> 153 </div> 154 </td> 155 </ItemTemplate> 156 </asp:Repeater> 157 </tr> 158 </table> 159 </td> 160 </tr> 161 </ItemTemplate> 162 <FooterTemplate> 163 </table> 164 </FooterTemplate> 165 </asp:Repeater> 166 <input type="hidden" id="hdnvalue" runat="server" value="0" /><!----存放scorllTop值--> 167 </div> 168 </div> 169 </div> 170 <script type="text/javascript"> 171 $(document).ready(function () { 172 TUILayout("form"); 173 //LoadImage(); 174 $(".div_img").gallery({ 175 gallerySize: { width: 90, height: 120 }, 176 fullView: "true" //ture为允许点击图像全屏浏览 177 }); 178 179 }); 180 function LoadImage() { 181 var jq_o_list = $("#observers div[@ref_id]"); 182 183 for (var i = 0 ; i < jq_o_list.length; i++) { 184 load_to(jq_o_list[i]); 185 } 186 } 187 188 function load_to(obj) { 189 var jq_o = $(obj); 190 Topevery.DUM.Web.AjaxFunction.GetEvtDefault(jq_o.attr("ref_id"), function (ajaxResult) { 191 var val = ajaxResult.value; 192 jq_o.empty(); 193 jq_o.append(val.Html); 194 }); 195 } 196 197 //$("#div_evt_img").gallery({ 198 // images: evt_img_list, 199 // thumbSize: { width: 65, height: 60 },//缩略图大小 200 // gallerySize: { width: 380, height: 280 },//画廊图(中间大图)大小 201 // thumbDisplayNum: 4,//缩略图显示数量 202 // scalingSize: { width: 360, height: 260 },//画廊图(中间大图)自动比例缩放最大大小 203 // fullView: "true" //ture为允许点击图像全屏浏览 204 //}); 205 206 function Reminder() { 207 NotSelectEvt("已经再次发送消息通知巡查员!"); 208 } 209 210 function review(id, type, content) { 211 if (confirmL("确认" + content + "吗?", function () { 212 Topevery.DUM.Web.AjaxFunction.ReviewImg(id, type); 213 $("#btnRef").click(); 214 215 })) { 216 } 217 } 218 </script> 219 220 </form> 221 </body> 222 </html> 223 <script type="text/javascript"> 224 window.onbeforeunload = function () { 225 var scrollPos; 226 if (typeof window.pageYOffset != ‘undefined‘) { 227 scrollPos = window.pageYOffset; 228 } 229 else if (typeof document.compatMode != ‘undefined‘ && 230 document.compatMode != ‘BackCompat‘) { 231 scrollPos = document.documentElement.scrollTop; 232 } 233 else if (typeof document.body != ‘undefined‘) { 234 scrollPos = document.body.scrollTop; 235 } 236 document.cookie = "scrollTop=" + scrollPos; //存储滚动条位置到cookies中 237 } 238 239 window.onload = function () { 240 if (document.cookie.match(/scrollTop=([^;]+)(;|$)/) != null) { 241 var arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/); //cookies中不为空,则读取滚动条位置 242 document.documentElement.scrollTop = parseInt(arr[1]); 243 document.body.scrollTop = parseInt(arr[1]); 244 } 245 } 246 </script>
以上是关于页面刷新滚动条位置不变的主要内容,如果未能解决你的问题,请参考以下文章