javascript|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 seconds, according to odd and even random rotation, of course, can also change the algorithm to increase 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 document.implementation.createDocument '!= ') Undefined ');
var ie = (typeof window.) ActiveXObject!= ' undefined '); function ImportXML (file) {if (Moz) {
xmldoc = Document.implementation.createDocument ("", "Doc", null);//create Firefox under XML Document object} else if (ie) {
xmldoc = new ActiveXObject ("MSXML2. domdocument.3.0 ");
Xmldoc.async = false; while (Xmldoc.readystate!= 4) {};//creates 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 the value under the Tupian,dizhi node
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; Achieve rotation
else if (IE) {
var src = xmlDoc.documentElement.selectNodes ("Tupian");
var href = xmlDoc.documentElement.selectNodes ("Dizhi")/Get the value document.getElementById ("Dizhi") under the Tupian,dizhi node.
href = href (i). Text;document.getelementbyid ("Tupian"). src = src (i). text; Implementation rotation}}