通過JAVASCRIPT讀取ASP設(shè)定的COOKIE
更新時間:2006年11月24日 00:00:00 作者:
復(fù)制代碼 代碼如下:
<%
Response.Cookies("Cookie1")("key1") = "KeyValue2"
%>
<script language="javascript">
String.prototype.get = function(name){
var reg = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)"),r;
if(r=this.match(reg))
return unescape(r[2]);
return null;
}
//獲取并返回 cookie 值
//不區(qū)分 cookieName 的大小寫
//dfltValue 為默認返回值
//不考慮子鍵
function RequestCookies(cookieName)
{
var lowerCookieName = cookieName.toLowerCase();
var cookieStr = document.cookie;
if (cookieStr == "")return "";
var cookieArr = cookieStr.split("; ");
var pos = -1;
for (var i=0; i<cookieArr.length; i++){
pos = cookieArr[i].indexOf("=");
if (pos > 0) {
if (cookieArr[i].substring(0, pos).toLowerCase() == lowerCookieName)
{
return unescape(cookieArr[i].substring(pos+1, cookieArr[i].length));
}
}
}
return "";
}
document.write("讀取名稱為 ab 的 cookie..." + RequestCookies("Cookie1").get("key1"));
-->
</script>
相關(guān)文章
原生js實現(xiàn)數(shù)字字母混合驗證碼的簡單實例
這篇文章主要介紹了原生js實現(xiàn)數(shù)字字母混合驗證碼的簡單實例,注釋很詳細,感興趣的小伙伴們可以參考一下2015-12-12
瀑布流的實現(xiàn)方式(原生js+jquery+css3)
這篇文章主要為大家詳細介紹了原生js+jquery+css3實現(xiàn)瀑布流的相關(guān)代碼,三種實現(xiàn)瀑布流的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-07-07
JS實現(xiàn)側(cè)邊欄鼠標經(jīng)過彈出框+緩沖效果
本文主要介紹了JS實現(xiàn)側(cè)邊欄鼠標經(jīng)過彈出框+緩沖效果的實現(xiàn)原理與方法步驟。具有很好的參考價值,下面跟著小編一起來看下吧2017-03-03
js實現(xiàn)的簡潔網(wǎng)頁滑動tab菜單效果代碼
這篇文章主要介紹了js實現(xiàn)的簡潔網(wǎng)頁滑動tab菜單效果代碼,可實現(xiàn)簡單的鼠標滑過tab標簽切換的功能,非常簡單實用,需要的朋友可以參考下2015-08-08
document.all還是document.getElementsByName?
document.all還是document.getElementsByName?...2006-07-07
Moment.js 不容錯過的超棒Javascript日期處理類庫
moment.js是一個輕量級并且健壯的js日期處理類庫,相信大家在javascript開發(fā)過程中,都自己動手寫過,或者使用google和百度搜索過相關(guān)的實現(xiàn)函數(shù)2012-04-04

