@ * Remember the position of the scroll bar when you click the button to refresh the page *@
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Window. onbeforeunload = function (){
Var scrollPos;
If (typeof window. pageYOffset! = 'Undefined '){
ScrollPos = window. pageYOffset;
}
Else if (typeof document. compatMode! = 'Undefined '&&
Document. compatMode! = 'Background '){
ScrollPos = document.doc umentElement. scrollTop;
}
Else if (typeof document. body! = 'Undefined '){
ScrollPos = document. body. scrollTop;
}
Document. cookie = "scrollTop =" + scrollPos; // store the position of the scroll bar to cookies.
}
Window. onload = function (){
If (document. cookie. match (/scrollTop = ([^;] +) (; | $ )/)! = Null ){
Var arr = document. cookie. match (/scrollTop = ([^;] +) (; | $)/); // If the cookie is not empty, the position of the scroll bar is read.
Document.doc umentElement. scrollTop = parseInt (arr [1]);
Document. body. scrollTop = parseInt (arr [1]);
}
}
</Script>