How does js dynamically load js files and read/write cookies through js scripts?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.