xml| Advertising
Recently updated the home page ads, ASP. NET advertising control is easy to achieve this, but the homepage is a static page, Lenovo advertising control principle decided to use javascript+xml to achieve this aspect of configuration, update the ads as long as the XML can be updated to facilitate the advertising rotation
The XML structure is as follows
<ad>
<tupian>http://www.seehaha.com/images/060901-150.100.2.gif</tupian>
<tupian>http://www.seehaha.com/xml/061009-300.100.jpg</tupian>
<dizhi>http://www.seehaha.com/plan/</dizhi>
<dizhi>http://www.seehaha.com/va.htm</dizhi>
</ad>
==
JScript files var now = new Date (); var min = now.getseconds (); var i; if (Min% 2) = = 1)//read number of seconds, according to odd and even random rotation, Of course, you can change this. The algorithm increases the number of XML nodes { i = 1; } else { i = 0; }var url = "Xml/ads.xml"; String.prototype.Trim = function () {return this.replace (^\s*) | ( \s*$)/g, ""); var xmldoc;//to determine whether Firefox or ie var Moz = (typeof document.implementation!= ' undefined ') && (typeof doc Ument.implementation.createDocument!= ' undefined '); var ie = (typeof window.) ActiveXObject!= ' undefined '); function ImportXML (file) {if (Moz) { xmldoc = Document.implementation.createDocument ("", "Doc", null);//create Firefox XML Document Object} else if (ie) { xmldoc = new ActiveXObject ("MSXML2. domdocument.3.0 "); Xmldoc.async = false; while (xmldoc.readystate!= 4) {};//Create an IE XML Document object} Xmldoc.load (file);} ImportXML (URL);/load Xmlfunction Updatetupiandizhi () {if (Moz) {var ad = Xmldoc.getelementsbytagname ("ad") [0]; var Tupian ; var _tupian = ad.getelementsbytagname ("Tupian") [i].firstchild.nodevalue; if (_tupian) Tupian = _tupian. Trim (); //Get Tupian,dizhi node value var dizhi; var _dizhi=ad.getelementsbytagname ("Dizhi") [i].firstchild.nodevalue; if (_dizhi) Dizhi = _ Dizhi. Trim (); document.getElementById (' Tupian '). href = tupian; document.getElementById (' Dizhi '). src = dizhi; //implementation rotation } else if (ie) {var src = XmlDoc.documentElement.selectNodes ("Tupian"); var href = xmlDoc.documentElement.selectNodes ("Dizhi");/Get TuThe value document.getElementById ("Dizhi") under the Pian,dizhi node. href = href (i). Text;document.getelementbyid ("Tupian"). src = src (i) .text; //implementation rotation }