var
flashCode;
var focus_width = 340
var focus_height = 226
var text_height = 24
var swf_height = focus_height + text_height
//
var texts = '' ;
var pics = '' ;
var links = '' ;
var adXml = new ActiveXObject( ' Msxml2.DOMDocument ' );
adXml.load( ' Xml/XMLFile.xml ' );
adXml.onreadystatechange = function () ... {
if(adXml.readyState==4)...{
var root = adXml.documentElement;
var items = root.childNodes;
for(var i=0;i<items.length;i++)
...{
texts = texts + items[i].childNodes[0].text;
links = links + items[i].childNodes[1].text;
pics = pics + items[i].childNodes[2].text;
if(i!=items.length-1)
...{
texts=texts + '|';
links = links + '|';
pics = pics + '|';
}
}
//
flashCode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">';
flashCode = flashCode + '<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="flash/pixviewer.swf"><param name="quality" value="high"><param name="bgcolor" value="#FFFFFF">';
flashCode = flashCode + '<param name="menu" value="false"><param name=wmode value="opaque">'
flashCode = flashCode + '<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">';
flashCode = flashCode + '<embed src="flash/pixviewer.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#FFFFFF" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
flashCode = flashCode + '</object>';
document.getElementById('flashDiv').innerHTML = flashCode;
}
}
var focus_width = 340
var focus_height = 226
var text_height = 24
var swf_height = focus_height + text_height
//
var texts = '' ;
var pics = '' ;
var links = '' ;
var adXml = new ActiveXObject( ' Msxml2.DOMDocument ' );
adXml.load( ' Xml/XMLFile.xml ' );
adXml.onreadystatechange = function () ... {
if(adXml.readyState==4)...{
var root = adXml.documentElement;
var items = root.childNodes;
for(var i=0;i<items.length;i++)
...{
texts = texts + items[i].childNodes[0].text;
links = links + items[i].childNodes[1].text;
pics = pics + items[i].childNodes[2].text;
if(i!=items.length-1)
...{
texts=texts + '|';
links = links + '|';
pics = pics + '|';
}
}
//
flashCode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">';
flashCode = flashCode + '<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="flash/pixviewer.swf"><param name="quality" value="high"><param name="bgcolor" value="#FFFFFF">';
flashCode = flashCode + '<param name="menu" value="false"><param name=wmode value="opaque">'
flashCode = flashCode + '<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">';
flashCode = flashCode + '<embed src="flash/pixviewer.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#FFFFFF" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
flashCode = flashCode + '</object>';
document.getElementById('flashDiv').innerHTML = flashCode;
}
}
这是一个常见的FLash广告代码,这两天把它从网页分离出来,用js调用xml来实现
涉及到的问题: 当用xmldocument的load时间加载xml文档时,出现问题,用到事件onreadystatechange,否则没有加载文档完毕,下面的调用会出现错误。onreadystatechange事件分四个阶段,分别是readystate属性的四个值。
第二个问题:起初直接用document.write方法在页面中执行,分离出来之后,在事件onreadystatechange里面document.write在重新执行时,会刷掉已加载的网页内容,所以改用getElementById().innerHTML的方法直接填充要加载的内容。