Many websites have automatic rotation of advertisements. I tried to write an image rotation, and the code and functions are very simple. I only support Internet Explorer, and I need to add some stuff to FF, users who need to know can refer to the boring recently. As many websites see automatic rotation of advertisements, they try to write an image rotation. The code and functions are very simple and only support IE, FF also needs to add some stuff.
Xml file: test. xml
The Code is as follows:
Http://www.163.com </neteasy>
Http://www.sina.com.cn </sina>
Http://www.sohu.com </sohu>
HTML
The Code is as follows:
Javascript
The Code is as follows:
Script
// Image rotation
Var a = 0;
Var xmlDoc;
Var image1 = document. getElementById ("image1 ");
Function loadxml (path)
{
XmlDoc = new ActiveXObject ("Microsoft. XMLDOM ");
XmlDoc. async = false;
XmlDoc. load (path );
}
Loadxml ("test. xml ");
Function changeImage ()
{
Var ad = xmlDoc. getElementsByTagName ("ad") [0];
If (a = ad. childNodes. length)
{
A = 0;
}
Var path = ad. childNodes [a]. getAttribute ("path ");
Var url = ad. childNodes [a]. text;
Image1.src = path;
Image1.onclick = function () {window. open (url );};
A + = 1;
SetTimeout ("changeImage ()", 1000 );
}
ChangeImage ();
Script