绑定到的innerHTML在MetroStyle应用程序从Javascript

问题描述:

我有一个DIV定义为:绑定到的innerHTML在MetroStyle应用程序从Javascript

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

和IM结合它与具有内容属性的对象。

现在我创建了使用外部资源,有时内容属性的对象将包含内容是这样的:

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

此抛出异常:

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. 

我明白例外,为什么它的发生,但现在我该如何做这项工作?

+1

按照错误消息的建议,如果浏览器支持它。我会担心,这会去掉'

查看this document的“动态添加HTML”部分您可能不得不使用execUnsafeLocalFunction来注入您要注入的特定HTML。此外,请查看this blog post关于创建可在Metro风格应用中使用的通用附加功能。

+0

将“execUnsafeLocalFunction”影响商店应用审批? – 2015-10-07 13:51:41