javascript 읽 기와 쓰기 XML 광고 교대 실현(IE,FF 호 환)

xml 구 조 는 다음 과 같다

<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    
var  Now  =  new  Date();   
var  Min  =  Now.getSeconds();
var  i;      
if((Min % 2) == 1)
// , , xml  
{
i = 1;

else
{  i = 0;  }
var url = "xml/ads.xml";
String.prototype.Trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
var xmlDoc;
// Firefox 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);
// FIREFOX XML

else if (ie) 
{   xmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
xmlDoc.async = false;
while( xmlDoc.readyState != 4) {};
// IE XML

xmlDoc.load(file);
}importXML(url);// xml
function updatetupiandizhi()
{
if (moz)
{
var ad = xmlDoc.getElementsByTagName("ad")[0];
var tupian;
var _tupian = ad.getElementsByTagName("tupian")[i].firstChild.nodeValue;
if (_tupian)   tupian = _tupian.Trim();  
// tupian,dizhi   
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; 
//   
} else if (ie)
{var src = xmlDoc.documentElement.selectNodes("tupian");
var href = xmlDoc.documentElement.selectNodes("dizhi");
// tupian,dizhi
document.getElementById("dizhi").href = href(i).text;
document.getElementById("tupian").src = src(i).text;  
//
}}

좋은 웹페이지 즐겨찾기