JS get DOM Object Ajax operations read and write cookies

Source: Internet
Author: User
Tags vars


var LF = {};
lf.version = ' 1.0.0 ';
Global functions
function $ (objname) {
return document.getElementById (objname);
}
function $name (objname) {
Return Document.getelementsbyname (objname);
}
function $tag (objname) {
Return document.getElementsByTagName (objname);
}
Advertising swf flashwrite (' sw/2009/homegrobuy.swf ', ' 950 ', ', ', ' Navigation ', ' # #ffffff ', ' menunum=0 ', ' Transparent ');
function Flashwrite (Url,w,h,id,bg,vars,win) {
var flashstr=
"<div align=" center "><object classid= ' clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 ' codebase= ' http:// fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0 ' width= ' "+w+" ' height= ' "+h+" ' id= ' "+id+" ' align= ' middle ' > ' +
"<param name= ' allowscriptaccess ' value= ' Always '/> '" +
"<param name= ' movie ' value= '" +url+ "'/>" +
"<param name= ' flashvars ' value= '" +vars+ "'/>" +
"<param name= ' wmode ' value= '" +win+ "'/>" +
"<param name= ' menu ' value= ' false '/>" +
"<param name= ' quality ' value= ' high '/>" +
"<param name= ' bgcolor ' value= '" +bg+ "'/>" +
"<embed src= '" +url+ "' flashvars= '" +vars+ "' wmode= '" +win+ "' menu= ' false ' quality= ' high ' bgcolor= '" +bg+ "' width= '" +w " + "' height= '" +h+ "' name= '" +id+ "' align= ' Middle '" allowscriptaccess= ' Always ' ' type= ' ' Application/x-shockwave-flash ' " pluginspage= ' http://www.macromedia.com/go/getflashplayer '/> ' +
"</object></div>";
document.write (FLASHSTR);
}
Advertising picture Imgwrite (' images/pic04.jpg ', ' 780 ', ' ', ', ' http://www.lfang.com/wzzt/2009/lgzt/');
function Imgwrite (url,w,h,linkurl) {
var flashstr= "";
if (linkurl== "")
Flashstr= "Else
Flashstr= "<a href=" "+linkurl+" ">" + " "+" </" A> ";
document.write (FLASHSTR);
}
Ajax operations
lf.ajax={
Getxmlhttp:function () {
var http_request;
if (window. XMLHttpRequest) {
Http_request = new XMLHttpRequest ();
if (Http_request.overridemimetype) {
Http_request.overridemimetype ("Text/xml");
}
}
else if (window. ActiveXObject) {
try {
Http_request = new ActiveXObject ("Msxml2.xmlhttp");
catch (e) {
try {
Http_request = new ActiveXObject ("Microsoft.XMLHTTP");
catch (e) {}
}
}
if (!http_request) {
Window.alert ("can" T create XMLHttpRequest object);
return null;
}
return http_request;
},
Loadajaxtab:function (URL) {//is generally div
try {
var xhttp=lf.ajax.getxmlhttp ();
Xhttp.open ("Get", url,false);
Xhttp.send (NULL);
if (xhttp.readystate = = 0) return "0 initialization ...";
if (xhttp.readystate = = 1) return "1 initialization ...";
if (xhttp.readystate = = 2) return "2 initialization ...";
if (xhttp.readystate = = 3) return "3 initialization ...";
if (xhttp.readystate = 4 && (xhttp.status==200)) {
var Restext=xhttp.responsetext;
if (restext!= "") return resText;
}
}catch (e) {
return e;
}
},
Datasubmit:function (Url,urlparameter,method) {//ajax Post submission data
try{
if (method== "") {method= "POST";}
var xhttp=lf.ajax.getxmlhttp ();
Xhttp.open (method, Url+urlparameter, false);
Xhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xhttp.send (NULL);
if (xhttp.readystate = = 0) return "0 initialization ...";
if (xhttp.readystate = = 1) return "1 initialization ...";
if (xhttp.readystate = = 2) return "2 initialization ...";
if (xhttp.readystate = = 3) return "3 initialization ...";
if (xhttp.readystate = = 4 && xhttp.status = =) return xhttp.responsetext;
}catch (e) {
return e;
}
}
};
Tools
Lf.util = {
Setcookie:function (Name,value) {//write cookies
var days = 30;
var exp = new Date ();
Exp.settime (Exp.gettime () + days*24*60*60*1000);
Document.cookie = name + "=" + Escape (value) + "expires=" + exp.togmtstring ();
},
Getcookie:function (name) {//Read cookies
var arr,reg=new RegExp ("(^|)" +name+ "= ([^;] *)(;|$)");
if (Arr=document.cookie.match (reg)) return unescape (arr[2]);
else return null;
},
Delcookie:function (name) {//delete cookies
var exp = new Date ();
Exp.settime (Exp.gettime ()-1);
var cval=getcookie (name);
if (cval!=null) document.cookie= name + "=" +cval+ "; expires=" +exp.togmtstring ();
},
Escape:function (HTML) {//filter HTML
html = html.replace (/&/g, "&");
html = html.replace (/</g, "<");
html = html.replace (/>/g, ">");
html = html.replace (/xa0/g, "");
html = html.replace (/x20/g, "");
return HTML;
}
};

Related Article

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.