vbscript&javascript 操作cookie
作者:lcx
来源:vbs小铺
javascript:
<SCRIPT language="javascript">
function setCookie(sVar, sVal){
theCookie = sVar + '=' + sVal + '; expires=Fri, 1 Jul 2010 09:45:27 UTC';
document.cookie = theCookie;
}
function getCookie(sVar){
cookies = document.cookie.split('; ');
for(var i = 1; i <= cookies.length; i++){
if(cookies[i - 1].split('=')[0] == sVar){
return cookies[i - 1].split('=')[1];
}
}
return '';
}
function doWrite(){
document.write('………………………html语句,嘿嘿…………………');
}
if(getCookie('Evil') == ''){
doWrite();
setCookie('Evil', 'Something');
}
</SCRIPT>
====================================================
vbscript:
<SCRIPT LANGUAGE="VBSCRIPT">
function GetCookie(sName)
DIM aCookie, i, aCrumb
GetCookie = ""
aCookie = split(document.cookie, "; ")
FOR i = LBOUND(aCookie) to UBOUND(aCookie)
aCrumb = split(aCookie(i), "=")
if sName = aCrumb(0) then
GetCookie = unescape(aCrumb(1))
EXIT FOR
end if
NEXT
end function
Sub SetCookie(sName, sValue)
document.cookie = sName & "=" & escape(sValue) & "; expires=Tue, 31 Dec 2009 23:59:59 GMT"
end Sub
sub DeleteCookie(sName)
document.cookie = sName & "=" + escape(sValue) & "; expires=Fri, 31 Dec 1999 23:59:59 GMT;"
end sub
</SCRIPT>
<form name="frm">
Name:<input type="text" name="cookiename"><br>
Value:<input type="text" name="cookievalue"><br>
<input type="button" value="create cookie" onclick="SetCookie me.form.cookiename.value, me.form.cookievalue.value"
language="vbscript">
<input type="button" value="get cookie" onclick="msgbox GetCookie(me.form.cookiename.value)"
language="vbscript">
<input type="button" value="delete cookie" onclick="DeleteCookie(me.form.cookiename.value)"
language="vbscript">