Javascript 有没有办法截取“document.write”?

Javascript 有没有办法截取“document.write”?,javascript,document.write,advertisement-server,Javascript,Document.write,Advertisement Server,我正在尝试延迟加载一些adserver代码 目前,我在页面上看到: <div class="ad"> <span>pos_1</span> </div> 然后,我想用文档的结果替换span。编写ad调用 有没有办法让它返回本应写入页面的字符串?我不明白为什么不能覆盖文档。write函数: document.write = function(str) { window.buf += str; } document.old_writ

我正在尝试延迟加载一些adserver代码

目前,我在页面上看到:

<div class="ad">
    <span>pos_1</span>
</div>
然后,我想用
文档的结果替换span。编写
ad调用


有没有办法让它返回本应写入页面的字符串?

我不明白为什么不能覆盖
文档。write
函数:

document.write = function(str) {
    window.buf += str;
}
document.old_write = document.write;

document.write = function (str) {
    // lalala
};
请参见此处:

必须在某个地方调用do_ad(pos)函数。为什么不把广告放在哪里呢

<div class="ad">
    <script>do_ad("pos_1");</script>
</div>

do_广告(“位置1”);

谢谢!现在我必须处理他们剧本中的其他失误。。。唉。。。这不是我想要的方式。。。因为广告服务器有三层:document.write('document.write('document.write('ad text')))。不过,它在一个深度上运行良好。可能是
<div class="ad">
    <script>do_ad("pos_1");</script>
</div>