嵌套在document.write中的document.write [英] document.write nested in document.write

查看:78
本文介绍了嵌套在document.write中的document.write的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个广告代码,第三方试图将其填充到"document.write"函数中,但该广告代码本身也包含document.write的内容,因此无法正常工作.有没有一种方法可以将这个广告代码推送到document.write的单个实例中?如果是这样,请帮助我解决这个问题,如果没有,还有其他选择吗?

I have an ad tag that a third party is trying to stuff inside of a 'document.write' function and it's not working because the ad tag itself also contains document.write's. Is there a way to shove this ad tag inside of a single instance of document.write? If so, please help me figure this out and if not, is there an alternative?

<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之类的框架来将这种类型的问题抽象化,

document.write is often concidered a harmful method, as it directly inserts content into the document file itself. You should edit the innerHTML of the tag where you want to insert the code, although I've heard that directly using innerHTML isn't the correct way either. The method is called insertNode, If I'm remembering correctly, but I'm not sure, because I'm usually abstracting this type of problem away using frameworks such as jQuery, where it is as simple as

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

我希望我的SO同事中的一些人可以使这篇文章更加准确,我自己会自己找一些东西,但是请考虑一下这是我的快速答案.

I hope that some of my fellow SO members can make this post more precise, I'll look some stuff up myself, but concider this to be my quick answer.

这篇关于嵌套在document.write中的document.write的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆