簡體   English   中英

嵌套在 document.write 中的 document.write

[英]document.write nested in document.write

我有一個廣告標簽,第三方試圖將其放入“document.write”函數中,但它不起作用,因為廣告標簽本身也包含 document.write。 有沒有辦法將這個廣告標簽推入 document.write 的單個實例中? 如果是這樣,請幫我解決這個問題,如果不是,還有其他選擇嗎?

<script type='text/javascript'>
var m3_u = 'http://this.that.com/adtag.js';
var m3_r = Math.floor(Math.random() * 99999999999);
var category='999';

if (!document.MAX_used) 
    document.MAX_used = ',';

document.write("<scr" + "ipt type='text/javascript' src='" + m3_u);
document.write("?c=" + category +"&amp;b=Sampletag&amp;p=ptnr&amp;key=4984cc8f3064e22a4e29fb2b3b2e9cb5");
document.write('&amp;cb=' + m3_r);

if (document.MAX_used != ',') 
    document.write("&amp;exclude=" + document.MAX_used);

document.write(document.charset ? '&amp;charset=' + document.charset :
(document.characterSet ? '&amp;charset=' + document.characterSet : ''));
document.write("&amp;loc=" + escape(window.location));

if (document.referrer) 
    document.write("&amp;referer=" + escape(document.referrer));
if (document.context) 
    document.write("&context=" + escape(document.context));
if (document.mmm_fo) 
    document.write("&amp;mmm_fo=1");

document.write("'><\/scr" + "ipt>");
</script>

document.write 通常被認為是一種有害的方法,因為它直接將內容插入到文檔文件本身中。 您應該編輯要插入代碼的標簽的innerHTML,盡管我聽說直接使用innerHTML 也不是正確的方法。 該方法稱為 insertNode,如果我沒記錯的話,但我不確定,因為我通常使用諸如 jQuery 之類的框架來抽象這類問題,它很簡單

$("#myelement").html("<script>...</script>")

我希望我的一些 SO 成員可以使這篇文章更准確,我會自己查找一些東西,但認為這是我的快速回答。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM