且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows 8 Phonegap 应用程序 JQuery 移动安全异常

更新时间:2023-02-26 22:32:34

我刚刚遇到了同样的问题.问题的关键似乎在于,当您从字符串创建元素时,WinJS 安全模型将不允许 JQuery dom 操作,例如使用 .html() 方法.

有关更多信息,请参阅以下内容:http://blogs.msdn.com/b/windowsappdev/archive/2013/04/01/windows-store-app-support-in-jquery-version-2-0.aspx>

http://net.tutsplus.com/tutorials/javascript-ajax/building-windows-store-applications-with-jquery-2-0/

总而言之,聪明的人已经在 J​​Query 2.0 中解决了这个问题.

所以我将考虑使用 JQuery 2.0,但它可以与 JQuery Mobile 一起使用吗?我还没有确定,所以我可能会考虑完全构建和附加 dom 元素,而不是使用 .html() 方法.

但请注意,我还没有尝试过这些方法中的任何一种,因此无法保证它们的有效性.

I have created a windows 8 project using the phonegap 2.9.0 and then tried to use JQuery mobile library within it. But I get the following security exception. Any idea how to resolve this ?.

Exception was thrown at line 4, column 7009 in ms-appx://c6a291ce-903f-47ab-b167-  cb8378ffb051/www/libs/jquery.core/jquery-1.9.1.min.js

 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.

 If there is a handler for this exception, the program may be safely continued.

I have just run into the same problem. It appears that the grist of the matter is that the WinJS security model won't allow the JQuery dom manipulation when you create elements from strings e.g. using the .html() method.

See the below for more information: http://blogs.msdn.com/b/windowsappdev/archive/2013/04/01/windows-store-app-support-in-jquery-version-2-0.aspx

http://net.tutsplus.com/tutorials/javascript-ajax/building-windows-store-applications-with-jquery-2-0/

In summary the clever people have produced a fix to this in JQuery 2.0.

So I'll be looking at using JQuery 2.0 but will it work with JQuery Mobile? I haven't determined that yet so I'll probably look at fully building and attaching the dom elements rather than using the .html() method.

But please note that I have not tried any of these approaches yet so cannot vouch for their validity.