vbscript&javascript 操作cookie

來源:互聯網
上載者:User

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">

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.