通過JAVASCRIPT讀取ASP設定的COOKIE
更新時間:2007年02月15日 00:00:00 作者:
<%
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>
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)文章
JavaScript實現(xiàn)動態(tài)數(shù)據(jù)可視化的示例詳解
動態(tài)數(shù)據(jù)可視化能夠?qū)⒋罅繑?shù)據(jù)以直觀、生動的方式呈現(xiàn),幫助用戶更好地理解和分析數(shù)據(jù),本文主要為大家介紹了如何使用JavaScript實現(xiàn)這一功能,需要的可以參考下2024-02-02
詳解Webpack實戰(zhàn)之構(gòu)建 Electron 應用
本篇文章主要介紹了Webpack實戰(zhàn)之構(gòu)建 Electron 應用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-12-12
django admin 使用SimpleUI自定義按鈕彈窗框示例
Django 后臺admin有大量的屬性和方法,擁有強大的功能和自定義能力,這篇文章主要介紹了django admin 使用SimpleUI自定義按鈕彈窗框示例,需要的朋友可以參考下2023-04-04
基于javascript實現(xiàn)樣式清新圖片輪播特效
這篇文章主要為大家詳細介紹了基于javascript實現(xiàn)樣式清新圖片輪播特效,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-03-03
uniapp常用路由跳轉(zhuǎn)的幾種方式(navigateTo、redirectTo...)
uni-app有兩種方式進行路由跳轉(zhuǎn),下面這篇文章主要給大家介紹了關(guān)于uniapp常用路由跳轉(zhuǎn)的幾種方式(navigateTo、redirectTo...),文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-11-11
excel操作之Add Data to a Spreadsheet Cell
excel操作之Add Data to a Spreadsheet Cell...2007-06-06

