我有一个 Div 定义为:
<div class="article-content" data-win-bind="innerHTML: content"></div>
我用一个具有内容属性的对象绑定(bind)到它。
现在我使用外部资源创建的对象,有时 content 属性会有这样的内容:
"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.
我了解异常及其发生的原因,但现在我该如何进行这项工作?
最佳答案
查看 this document 的“动态添加 HTML”部分您可能必须使用 execUnsafeLocalFunction注入(inject)您要注入(inject)的特定 HTML。另外,查看 this blog post关于创建适用于 Metro 风格应用程序的通用附加函数。
关于javascript - 从 Javascript 绑定(bind)到 MetroStyle 应用程序中的 InnerHTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11925376/