Using jQuery with Windows 8 Metro JavaScript App causes security error

前端 未结 11 1618
孤城傲影
孤城傲影 2020-11-29 21:03

Since it sounded like jQuery was an option for Metro JavaScript apps, I was starting to look forward to Windows 8 dev. I installed Visual Studio 2012 Express RC and started

相关标签:
11条回答
  • 2020-11-29 21:33

    I've done a little more investigation, and wanted to clarify a couple of things.

    The error you see is in the JavaScript console, not an actual exception. The jQuery code continues to run just fine. It's actually something the underlying system is logging, not an error or exception.

    There's no reason to patch jQuery or do anything else - it's a noisy system component, not an actual error.

    0 讨论(0)
  • 2020-11-29 21:34

    After the recent //Build/ 2012 conference and this talk talks about using jQuery in Windows 8 Store Apps. Specifically, they talk about the exact exception of script injection inside innerHTML, and talk about the updates done in this.

    The company AppendTo also officially unveiled jQuery for Windows 8 during that talk. It looks neat from the demonstration given in the talk in the link about.

    They also say that it is not a good idea to get jQuery from CDN for Windows 8 Apps in Local Context!

    0 讨论(0)
  • 2020-11-29 21:39

    If you still need it, I am writting a reimplementation of the Deferred object found in jQuery.

    Once finished it should be 100% compatible with jQuery's Deferred object. Right now it's quite complete but needs some testing.

    See this.

    Hope this will help!

    That said, I think it should be a good idea to learn how to use Microsoft's implementation of Promise instead of jQuery when working on Windows 8 apps.

    0 讨论(0)
  • 2020-11-29 21:39

    I believe this is the same restriction as imposed by Content Security Policy (CSP). That specific case was addressed in jQuery 1.8.0. Does the problem still occur there?

    https://github.com/jquery/jquery/commit/dc83072878ed9636c8158a014bd9fa4acc1ccce3

    0 讨论(0)
  • 2020-11-29 21:41

    For what it's worth, I've ported the majority of jQuery core to wrap the native WinJS library. It's lightweight and provides just about everything that jQuery does with the addition of some plugins for badges, notifications, etc.

    It is a work in progress, but I'm trying to get some people to join in the fun.

    https://github.com/rmcvey/winjq

    Quick write-up (documentation is being added to): http://practicaljs.com/jquery-in-windows-8-apps/

    0 讨论(0)
  • 2020-11-29 21:42

    I was able to eliminate the problem by finding all places in jQuery that set innerHTML and wrapping the value being set with toStaticHTML().

    So, for example:

    div.innerHTML = "   <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
    

    became:

    div.innerHTML = toStaticHTML("   <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>");
    

    To be safe, I've also defined this just before jQuery is defined, in case the file is used in a normal browser:

    window.toStaticHTML = window.toStaticHTML || function (s) { return s; };
    

    To me that seemed to be the safest change, although it required patching a dozen places in jQuery. (don't use a var statement before the toStaticHTML)

    0 讨论(0)
提交回复
热议问题