2011-01-20 14 views
2

私は、現時点ではこれを持っているページでは...いくつかのAdServerコード怠惰な負荷に`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広告呼び出しの結果とスパンを交換したいです。

ページに書き込まれた文字列を返す方法はありますか?

+0

の可能重複 - (http://stackoverflow.com/questions/1536970/javascript-controlling-the-insertion-point-for-document-write)はJavaScriptのdocument.writeの挿入ポイントを制御] –

答えて

6

あなたがdocument.write機能を上書きすることはできませんなぜ私は表示されません。

document.old_write = document.write; 

document.write = function (str) { 
    // lalala 
}; 

はこちらをご覧ください:http://www.jsfiddle.net/N9hXy/

+0

ありがとう!今、私は彼らのスクリプトの他の失敗に対処しなければならない...一口 – SeanJA

+1

悲しいかな...これは私が望んでいたようにはうまくいきませんでした...広告サーバーは3レベル深いので、 'document.write ' ')) '; '。しかし、それは単一の深さのためにうまくいった。 – SeanJA

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

+1また、この前に 'window.buf'を必ず定義してください。 –

0

do_ad(POS)関数がどこかに呼び出さなければなりません。なぜ広告を表示するのか?

<div class="ad"> 
    <script>do_ad("pos_1");</script> 
</div> 
関連する問題