Heim >Web-Frontend >js-Tutorial >通过JAVASCRIPT读取ASP设定的COOKIE_javascript技巧

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 19:23:52909Durchsuche
复制代码 代码如下:

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>

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn