function QueryString() {
var data = [];
this.Read = function() {
var aPairs, aTmp;
var queryString = new String(window.location.search);
queryString = queryString.substr(1, queryString.length); //remove "?"
aPairs = queryString.split("&"); for (var i = 0; i < aPairs.length; i++) {
aTmp = aPairs[i].split("=");
data[aTmp[0]] = aTmp[1];
}
} this.GetValue = function(key) {
return data[key];
}
this.SetValue = function(key, value) {
if (value == null)
delete data[key];
else
data[key] = value;
}
this.ToString = function() {
var queryString = new String(""); for (var key in data) {
if (queryString != "")
queryString += "&"
if (data[key])
queryString += key + "=" + data[key];
}
if (queryString.length > 0)
return "?" + queryString;
else
return queryString;
}
this.Clear = function() {
delete data;
data = [];
}
} function Cookies() {
var cookieData = []; this.Read = function() {
var pairs = new String(window.document.cookie).split(";");
var tmp, cookieName, keyName;
for (var i = 0; i < pairs.length; i++) {
tmp = pairs[i].split("="); if (tmp.length == 3) {
cookieName = new String(tmp[0]);
cookieName = cookieName.replace(" ", ""); if (cookieData[cookieName] == null)
cookieData[cookieName] = [];
cookieData[cookieName][tmp[1]] = unescape(tmp[1]);
} else //length = 2
{
keyName = tmp[0];
keyName = keyName.replace(" ", "");
if (keyName.substring(0, 12) != "ASPSESSIONID") {
if (cookieData[""] == null)
cookieData[""] = [];
cookieData[""][keyName] = unescape(tmp[1]);
}
}
} } this.GetValue = function(cookie, key) {
if (cookieData[cookie] != null)
return cookieData[cookie][key];
else
return null;
}
this.SetValue = function(cookie, key, value) {
if (cookieData[cookie] == null)
cookieData[cookie] = [];
cookieData[cookie][key] = value;
}
this.Write = function() { var toWrite;
var thisCookie;
var expireDateKill = new Date();
var expireDate = new Date();
expireDate.setYear(expireDate.getFullYear() + 10);
expireDateKill.setYear(expireDateKill.getFullYear() - 10); var pairs = new String(window.document.cookie).split(";");
var tmp, cookieName, keyName;
for (var i = 0; i < pairs.length; i++) {
tmp = pairs[i].split("=");
if (tmp.length == 3) {
window.document.cookie = tmp[0] + "=" + tmp[1] + "='';expires=" + expireDateKill.toGMTString();
} else {
keyName = tmp[0];
keyName = keyName.replace(" ", "");
if (keyName.substring(0, 12) != "ASPSESSIONID")
window.document.cookie = keyName + "='';expires=" + expireDateKill.toGMTString();
}
} for (var cookie in cookieData) {
toWrite = "";
thisCookie = cookieData[cookie];
for (var key in thisCookie) {
if (thisCookie[key] != null) {
if (cookie == "")
toWrite = key + "=" + thisCookie[key];
else
toWrite = cookie + "=" + key + "=" + escape(thisCookie[key]);
toWrite += "; expires=" + expireDate.toGMTString();
window.document.cookie = toWrite;
}
}
}
}
}

js访问url和cookie的更多相关文章

  1. JS访问或设置cookie的方法+跨域调用方法

    无意中从163网站获取的JS访问或设置cookie的方法,Log到日志上以防遗忘 //COOKIE功能检查function fCheckCookie(){    if(!navigator.cooki ...

  2. android webview带cookie访问url

    问题描述在原生和h5混合开发的时候会遇到这么一个问题,用webview加载某个url时,你只是app登录了账号,但是网页却没有,所有会禁止访问此url,webview就会显示白屏.所以要访问此url, ...

  3. HttpHelps类,用来实现Http访问,Post或者Get方式的,直接访问,带Cookie的,带证书的等方式,可以设置代理

    原文地址:http://blog.csdn.net/cdefg198/article/details/8315438 万能框架:http://www.sufeinet.com/forum.php?mo ...

  4. js 第四章 cookie的操作

    js 第四章 cookie的操作 一.学习要点 掌握cookie的简单应用 二. js 第四章 cookie的操作 了解cookie 什么是cookie? cookie 是存储于访问者的计算机中的变量 ...

  5. jquery + node 通过 CORS 实现跨域访问,支持cookie和自定义header

    跨域有多种方式,现在的情况看来还是CORS更适合一些,有很多优点,比如浏览器正式支持.支持post.可以控制跨域访问的网站等. 我们来看看node如何实现cors方式的跨域.在网上找到了一些代码,考过 ...

  6. 使用nutz框架,找不到入口函数,访问Url报404

    案例 今天在跟着nutz框架教程去配置demo时,发现访问URL找不到入口函数,出现了Search mapping for path=/user/count : NOT Action match 异常 ...

  7. js javascript 获取url,获得当前页面的url,静态html文件js读取url参数

    获得当前页面的url window.location.href 静态html文件js读取url参数 location.search; //获取url中"?"符后的字串 下边为转载的 ...

  8. js获取URL中的参数

    js获取URL中的一些参数的意思 location对象 含有当前URL的信息. 属性 href 整个URL字符串. protocol 含有URL第一部分的字符串,如http: host 包含有URL中 ...

  9. 使用Node.JS访问Hyperledger Fabric的gRPC服务

    在即将正式发布的Hyperledger Fabric SDK 1.0中,Hyperledger Fabric通过gRPC提供服务接口以取代现有的REST API.本文介绍了如何使用Node.JS访问H ...

随机推荐

  1. Guava Files 源码分析(一)

    Files中的工厂 Files类中对InputStream, OutputStream以及Reader,Writer的操作封装了抽象工厂模式,抽象工厂是InputSupplier与OutputSupp ...

  2. 【12c】root container 和 pdb 的一些差别

      Where\what ? root pdb 备注 Control files and redo log files Y belongs to the CDB and not to a spec ...

  3. longest-substring-with-at-least-k-repeating-characters

    https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/ public class S ...

  4. HDU 3910 (13.10.31)

    Description Maybe you know “San Guo Sha”, but I guess you didn’t hear the game: “Liang Guo Sha”! Let ...

  5. html 中shadow DOM 的使用

    什么是shadow DOM? An important aspect of web components is encapsulation — being able to keep the marku ...

  6. Android网络缓存的实现思路

    在开发群里有多位同学问到了关于Android中网络缓存的问题.事实上不管是Android还是iOS,缓存的大致思路都是同样的,以下就几种情况下的缓存做一个大致的介绍.顺便说一下有些开源的网络请求框架已 ...

  7. dobbo 服务配置详解(解决超时重试问题)

    <!-- reference method -->     <dubbo:reference interface="com.xx.XxxService">  ...

  8. [Javascript] Hositing

    First, memory is set aside for all necessary variables and declared functions. Function expression n ...

  9. [Backbone]2. More detail in Models

    Our Appointment model doesn't seem too useful yet. Add two default attributes, title as the string & ...

  10. 一些面试基本知识(Android篇一)

    Android Activity设计模式之MVC模式(介绍MVP之前的引子) 參考博客.文章 http://www.cnblogs.com/liqw/p/4175325.html MVC即Model- ...