我试图延迟加载一些广告服务器代码...有没有办法拦截`document.write`?
在网页上我有这样的时刻:
<div class="ad">
<span>pos_1</span>
</div>
我然后再通过并拉出所有的广告应该是对的页面,称他们的JavaScript包含文件,这让我这个可爱的烂摊子:
function do_ad(pos){
switch(pos){
case 'pos_1':
document.write('first ad text');
document.write('first ad more text');
//and so on for many many lines
break;
case 'pos_2':
document.write('second ad text');
document.write('second ad more text');
//and so on for many many lines
break;
}
}
我再想用document.write
广告调用的结果来替换跨度。
有没有办法让它返回已写入页面的字符串?
的可能重复的[JavaScript的 - 控制装置,用于文件撰写插入点](http://stackoverflow.com/questions/1536970/javascript-controlling-the-insertion-point-for-document-write) –