[HTML]
//支援所有瀏覽器
<script type = "text/javascript">
//chrome和firefox不支援
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" %>
參考連結
http://www.dotblogs.com.tw/atowngit/archive/2011/03/03/21643.aspx
http://www.aspsnippets.com/Articles/ASPNet-MaintainScrollPositionOnPostback-not-working-in-Firefox-and-Chrome.aspx
//支援所有瀏覽器
<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;
}
};
</script>//chrome和firefox不支援
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" %>
參考連結
http://www.dotblogs.com.tw/atowngit/archive/2011/03/03/21643.aspx
http://www.aspsnippets.com/Articles/ASPNet-MaintainScrollPositionOnPostback-not-working-in-Firefox-and-Chrome.aspx
留言
張貼留言