首頁 >web前端 >js教程 >通过JAVASCRIPT读取ASP设定的COOKIE_javascript技巧

通过JAVASCRIPT读取ASP设定的COOKIE_javascript技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-05-16 19:23:52899瀏覽
复制代码 代码如下:

Response.Cookies("Cookie1")("key1") = "KeyValue2"
%>

<script> <br><br><BR>String.prototype.get = function(name){ <BR>var reg = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)"),r; <BR>if(r=this.match(reg)) <BR>return unescape(r[2]); <BR>return null; <BR>} <br><br><BR>//获取并返回 cookie 值 <BR>//不区分 cookieName 的大小写 <BR>//dfltValue 为默认返回值 <BR>//不考虑子键 <BR>function RequestCookies(cookieName) <BR>{ <BR> var lowerCookieName = cookieName.toLowerCase(); <BR> var cookieStr = document.cookie; <br><br> if (cookieStr == "")return ""; <br><br> <BR> var cookieArr = cookieStr.split("; "); <BR> var pos = -1; <BR> for (var i=0; i<cookieArr.length; i++){ <BR> pos = cookieArr[i].indexOf("="); <BR> if (pos > 0) { <BR> if (cookieArr[i].substring(0, pos).toLowerCase() == lowerCookieName) <BR> { <BR> return unescape(cookieArr[i].substring(pos+1, cookieArr[i].length)); <BR> } <BR> } <BR> } <br><br> return ""; <BR>} <br><br>document.write("读取名称为 ab 的 cookie..." + RequestCookies("Cookie1").get("key1")); <BR>--> <BR></script>

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn