I've been bored recently. I saw that many websites have automatic rotation of advertisements. I tried to write an image rotation myself. The code and function are very simple. It only supports IE, and FF needs to add some stuff.
xml file: test.xml
< ;?xml version="1.0" encoding="gb2312"?>
http://www.163.com< /neteasy>
http://www.sina.com.cn
http://www.sohu.com
HTML
javascript
<script> <br>//Image rotation<br>var a = 0; <br>var xmlDoc; <br>var image1 = document.getElementById ("image1"); <br>function loadxml(path) <br>{ <br>xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); <br>xmlDoc.async = false; <br>xmlDoc.load(path ); <br>} <br>loadxml("test.xml"); <br>function changeImage() <br>{ <br>var ad = xmlDoc.getElementsByTagName("ad")[0]; <br> if(a == ad.childNodes.length) <br>{ <br>a=0; <br>} <br>var path = ad.childNodes[a].getAttribute("path"); <br>var url = ad.childNodes[a].text; <br>image1.src = path; <br>image1.onclick = function(){window.open(url);}; <br>a =1; <br> setTimeout("changeImage()",1000); <br>} <br>changeImage(); <br></script>