用 cookie 记录滚动条的位置, 用 cookie 感觉总不太好. <script language=javascript> function setCookie(name,value) { var Days = 2; //此 cookie 将被保存 2 分钟 var exp = new Date(); //new Date("December 31, 9998"); exp.setTime(exp.getTime() + Days*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); } function getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return unescape(arr[2]); else return null; } function window.onbeforeunload() { var a = document.body.scrollTop; var b = document.body.scrollLeft; if (a == 0 && b == 0) setCookie("meizz", wlh +"@"+ a +"@"+ b); } function window.onload() { var s = getCookie("meizz"); if (s) { s = s.split("@"); if (wlh == s[0]) { document.body.scrollTop = s[1]; document.body.scrollLeft = s[2]; } } } var wlh = window.location.href; wlh = wlh.substring(wlh.lastIndexOf("/")+1, wlh.length); </script>
<script language=javascript>
function setCookie(name,value)
{
var Days = 2; //此 cookie 将被保存 2 分钟
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)) return unescape(arr[2]);
else return null;
}
function window.onbeforeunload()
{
var a = document.body.scrollTop;
var b = document.body.scrollLeft;
if (a == 0 && b == 0)
setCookie("meizz", wlh +"@"+ a +"@"+ b);
}
function window.onload()
{
var s = getCookie("meizz");
if (s)
{
s = s.split("@");
if (wlh == s[0])
{
document.body.scrollTop = s[1];
document.body.scrollLeft = s[2];
}
}
}
var wlh = window.location.href;
wlh = wlh.substring(wlh.lastIndexOf("/")+1, wlh.length);
</script>