首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套在document.write中的document.write

嵌套在document.write中的document.write
EN

Stack Overflow用户
提问于 2011-09-17 05:52:53
回答 1查看 1.6K关注 0票数 2

我有一个广告标签,第三方试图将其放在' document.write‘函数中,但它不起作用,因为广告标签本身也包含Document.write。有没有办法将这个广告标签塞到document.write的单个实例中?如果是,请帮我弄清楚,如果不是,有没有其他选择?

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2011-09-17 06:02:19

document.write通常被认为是一种有害的方法,因为它直接将内容插入文档文件本身。您应该编辑要在其中插入代码的标记的innerHTML,尽管我听说直接使用innerHTML也不是正确的方法。如果我没记错的话,这个方法叫做insertNode,但我不确定,因为我通常使用诸如jQuery这样的框架来抽象这种类型的问题,在这些框架中,它就像

代码语言:javascript
复制
$("#myelement").html("<script>...</script>")

我希望我的一些同事能让这篇文章更精确,我会自己去查一些东西,但请相信这是我的快速答案。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7450762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档