jsloader
/** * 用作cookie 代理相关的函数操作, * 需要 Ffunction.js 否则需要将 cookie 部分copy出来 */ //cookie代理ifram function FCookieFrame(idPrefix,src,fun) { this._cf = document.createElement("iframe"); this._cf.id = idPrefix+"_cookie_frame"; this._cf.name = idPrefix+"_cookie_frame"; this._cf.style.display = "none"; document.getElementsByTagName("body")[0].appendChild(this._cf); this._cf.src = src; if(typeof fun == "function") { FaddEvent(this._cf,'load',fun); } } //获取代理中的cookie //需要有一个代理页面,同时页面中需要有 g 函数 FCookieFrame.prototype.getCookie = function (name) { try { return this._cf.contentWindow.g(name); }catch(e){ return null; } } //清除cookie,由于是代理的,清除是需要对应的路径下清理,不能使用统一的函数 FCookieFrame.prototype.clearCookie = function (name,path,domain) { if (this.getCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "; path=/") + ((domain) ? "; domain=" + domain : "; domain=data.auto.qq.com") + ";expires=Fri, 02-Jan-1970 00:00:00 GMT"; } } function FaddEvent(e,evt,fn,isID) { if(isID==true) e=Fid(e); if(!Fempty(e.attachEvent) && (typeof(e.attachEvent)=="function" || typeof(e.attachEvent)=="object")) e.attachEvent("on"+evt,fn); else if(!Fempty(e.addEventListener) && (typeof(e.addEventListener)=="function" || typeof(e.addEventListener)=="object")) e.addEventListener(evt,fn,false); } function Fempty(v){ if(v!=null && (typeof(v)=='object' || typeof(v)=='function')) return false; return ((""==v || undefined==v || null==v)?true:false); } //应用示例: //代理页面实现如下: /* try { //降到根域 document.domain='qq.com'; }catch(e){} function g(n) { var a = document.cookie.match(new RegExp("(^|; ?)"+n+"=([^;]*)(;|$)")); return a == null?"":unescape(a[2]); } */ //应用页面: /* //设置 cookie document.domain = "qq.com"; var expires = new Date(); expires.setTime(new Date ().getTime() + 1800000);//半小时 Cookie.setCookie("autoapp_test","111111111",expires,"\/cookie","qq.com"); //获取cookie var cf = new FCookieFrame("test","http://auto.qq.com/cookie/cookie.shtml",function(){ //alert("load finished"); alert(cf.getCookie("autoapp_test")); }); */
功能:支持在根path下(/) 获取子path下的cookie (/cookie)