function window.onload()
{ if(arr=document.cookie.match(/scrollTop=([^;]+)(;|$)/)) document.documentElement.scrollTop=parseInt(arr[1]); } function window.onbeforeunload() { document.cookie="scrollTop="+document.documentElement.scrollTop; } 注:用document.body.scrollTop 也可以,但是如果网页为<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www./TR/2000/REC-xhtml1-2000012 ... itional.dtd"> 那么document.body.scrollTop 总是为0 通用的方法
var bodySL, bodyST;
if(window.pageXOffset) { bodySL=window.pageXOffset; } else if(document.documentElement&&document.documentElement.scrollLeft) { bodySL=document.documentElement.scrollLeft; } else if(document.body) { bodySL=document.body.scrollLeft; //author: meizz } if(window.pageYOffset) { bodyST=window.pageYOffset; } else if(document.documentElement&&document.documentElement.scrollTop) { bodyST=document.documentElement.scrollTop; } else if(document.body) { bodyST=document.body.scrollTop; } var bodyCW, bodyCH; if(window.innerWidth) { bodyCW=window.innerWidth; } else if(document.documentElement&&document.documentElement.clientWidth) { bodyCW=document.documentElement.clientWidth; } else if(document.body) { bodyCW=document.body.clientWidth; //author: meizz } if(window.innerHeight) { bodyCH=window.innerHeight; } else if(document.documentElement&&document.documentElement.clientHeight) { bodyCH=document.documentElement.clientHeight; } else if(document.body) { bodyCH=document.body.clientHeight; } |
|
来自: eeason > 《JS & HTML》