在Javascript中绑定到MetroStyle App中的InnerHTML [英] Binding to InnerHTML in MetroStyle App from Javascript

查看:121
本文介绍了在Javascript中绑定到MetroStyle App中的InnerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Div定义为:

I have a Div Defined as:

<div class="article-content" data-win-bind="innerHTML: content"></div>

以及im与具有content属性的对象绑定。

and im binding to it with an object which has content property.

现在是我使用外部资源创建的对象,有时content属性会包含如下内容:

now the object i create using external resources and sometimes the content property would has content like this :

"some text <iframe width="560" height="315" src="youtubelink" frameborder="0" allowfullscreen></iframe>"

这个抛出异常:

this throw exception:

Unable to add dynamic content. A script attempted to inject dynamic content, or elements previously modified dynamically, that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content, or explicitly create elements and attributes with a method such as createElement. 

我了解异常及其发生的原因,但现在该怎么做?

I understand the exception and why its happening but now how do i make this work ?

推荐答案

查看本文档您可能需要使用 execUnsafeLocalFunction 注入您要注入的特定HTML。另外,请查看此博客文章创建可在Metro风格应用中使用的通用附加功能。

Check out the "Dynamically adding HTML" section of this document You may have to use execUnsafeLocalFunction to inject the particular HTML that you're trying to inject. Also, check out this blog post on creating a generic append function that will work in Metro style apps.

这篇关于在Javascript中绑定到MetroStyle App中的InnerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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