简体   繁体   English

如何在不插入dom的情况下加载mbox内容

[英]How do I load an mbox content without inserting into the dom

I'm trying to interface with Adobe Test & Target because I want to load JSON rather than markup through my mbox. 我正在尝试与Adobe Test&Target进行接口连接,因为我想通过我的mbox加载JSON而不是标记。 I want to load some mbox content into javascript and manually add it to the DOM. 我想将一些mbox内容加载到javascript中,然后手动将其添加到DOM中。 I have searched all over for full documentation of the mbox.js but I can't find anything other than the very basics. 我到处搜索了mbox.js的完整文档,但是除了基本内容外,我找不到其他任何内容。 It describes how to use mboxDefine() and mboxUpdate to target a specific dom element. 它描述了如何使用mboxDefine()mboxUpdate定位特定的dom元素。 Is there a function that just returns the content? 是否有只返回内容的函数? ``` ```

T&T does not offer a function to assign the response to a javascript variable. T&T不提供将响应分配给javascript变量的功能。 Basically the way it works is mbox.js builds a url to their server and then then outputs a script include tag. 基本上,它的工作方式是mbox.js构建指向其服务器的url,然后输出脚本include标签。 This is done to get around the same origin policy limitations (cross-site scripting). 这样做是为了解决相同的原始策略限制(跨站点脚本)。

In order to handle whatever is in the html offer, they put it in their own javascript variable on their server and then output it as that as the response. 为了处理html提供的内容,他们将其放在服务器上自己的javascript变量中,然后将其作为响应输出。 However, they also have the response output the code that updates the target element. 但是,它们也将响应输出的代码更新为目标元素。 So there's nothing you can do to actually stop them from updating the target element with the html offer contents. 因此,您无法采取任何行动来阻止他们使用html商品内容更新目标元素。 They simply don't expose that. 他们只是不公开这一点。

However , you don't have to put html in an html offer. 但是 ,您不必将html放在html报价中。 You can put json (javascript) in an html offer. 您可以将json(javascript)放在html报价中。 Just do like 只是喜欢

html offer 'myJsonMbox' (in interface) html提供“ myJsonMbox”(在界面中)

<script type='text/javascript'>
var myJsonString = "[json string]";
</script>

Then on your page (inside your body tag, but before your code that wants to use it) you'd have the regular mbox code: 然后在页面上(在body标记内,但在要使用它的代码之前),您将获得常规的mbox代码:

<div class='mboxDefault'></div>
<script type='test/javascript'>
mboxCreate('myJsonMbox');
</script>

And then somewhere after that, where you're wanting to do something with it, that myJsonString is there for you to reference. 然后在那之后的某个地方,您想要对其进行处理, myJsonString可供您参考。 Or, you can do it with the mboxDefine and mboxUpdate sometime after page load, if you prefer. 或者,可以根据mboxDefine在页面加载后的某个时间使用mboxDefinemboxUpdate进行操作。

Is there some particular reason why you don't think this will work for you? 您是否有某些特定原因导致您认为这不适合您?

You can: 您可以:

a- Insert JS code you are going to use to manually manipulate the DOM a-插入要用于手动操作DOM的JS代码

b- Insert CSS code you can use to alter the original HTMl or the newly added HTML. b-插入可用于更改原始HTM1或新添加的HTML的CSS代码。

c- Insert a call to a 3rd party script that will load content from a 3rd party server if needed, or the same server. c-插入对第三方脚本的调用,该脚本将在需要时从第三方服务器或同一服务器加载内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM