JavaScript运行时错误:无法添加动态内容 [英] JavaScript runtime error: Unable to add dynamic content
问题描述
我正在制作一个javascript Metro应用程序,并且有一些类似这样的代码:
I'm making a javascript metro app and have some code like this:
<script>
document.writeln(foo());//this line is trouble
</script>
当我尝试跑步时,它给了我一个相当长的错误:
and when I tried to run, it gave me a rather long error:
ms-appx://a375ffac-3b69-475a-bd53-ee3c1ccf4c4e/default.html
Unhandled exception at line 20, column 9 in ms-appx://a375ffac-3b69-475a-bd53-ee3c1ccf4c4e/default.html
0x800c001c-JavaScript运行时错误:无法添加动态内容. 脚本试图注入动态内容或先前的元素 动态修改,可能是不安全的.例如,使用 innerHTML属性以添加脚本或格式错误的HTML会生成此 例外.使用toStaticHTML方法过滤动态内容,或者 使用以下方法显式创建元素和属性: createElement.有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=247104 .
0x800c001c - JavaScript runtime error: 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. For more information, see http://go.microsoft.com/fwlink/?LinkID=247104.
我该如何解决?
推荐答案
%29.aspx>文档我会尝试:
regarding to the docs I would try :
document.writeln(window.toStaticHTML(foo()));
这篇关于JavaScript运行时错误:无法添加动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!