In front-end development, we can't help but use read/write cookies and dynamically introduce js scripts and other related operations. How can we achieve this? See the following js functions: [javascript] varJsHelper {CreateJS: function (url) {varhdocument. getElementsByTagName... Synt
In front-end development, we can't help but use read/write cookies and dynamically introduce js scripts and other related operations. How can we achieve this? See the following js functions:
[Javascript] var JsHelper = {
CreateJS: function (url ){
Var h = document. getElementsByTagName ("head") [0];
Var s = document. createElement ("SCRIPT ");
S. charset = "UTF-8 ";
S. src = url;
H. appendChild (s );
},
SetCookieByDays: function (name, value, Days, domainValue ){
Var cookieValue = name + "=" + escape (value );
If (domainValue! = Null) cookieValue + = ";
Domain = "+ domainValue;
If (Days! = Null & Days! = 0 ){
Var exp = new Date ();
Exp. setTime (exp. getTime () + Days x 24x60*60*1000 );
CookieValue + = "; expires =" + exp. toGMTString ();
}
Document. cookie = cookieValue;
},
GetCookie: function (name ){
Var arr = document. cookie. match (new RegExp ("(^ |)" + name + "= ([^;] *) (; | $ )"));
If (arr! = Null) return unescape (arr [2]);
Return null;
},
QueryString: function (item ){
Var sValue = location. search. match (new RegExp ("[\? \ &] "+ Item +" = ([^ \ &] *) (\ &?) "," I "));
Return sValue? SValue [1]: sValue
}
};
From the pure soul