您的位置:首页 > Web前端 > JavaScript

[转载] cookie、JS记录及跳转到页面原来的位置

2014-01-08 13:44 435 查看
额....如下

<!-- 定位页面的 Cookie

function SetCookie(sName, sValue)
{
date = new Date();
s = date.getDate();
date.setDate(s+1);            //expire time is one month late!, and can't be current date!
document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}
function GetCookie(sName)
{
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0]) {
return unescape(aCrumb[1]);}
}

// a cookie with the requested name does not exist
return null;
}

function fnLoad()
{
document.documentElement.scrollLeft = GetCookie("scrollLeft");
document.documentElement.scrollTop = GetCookie("scrollTop");
}

function fnUnload()
{
SetCookie("scrollLeft", document.documentElement.scrollLeft)
SetCookie("scrollTop", document.documentElement.scrollTop)
}

window.onload = fnLoad;
window.onunload = fnUnload;

// -->
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: