Javascript + xml implement simple image rotation (only supports IE) _ javascript skills

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

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.