Using jQuery with Windows 8 Metro JavaScript App causes security error

前端 未结 11 1645
孤城傲影
孤城傲影 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条回答
  •  猫巷女王i
    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 = "   
    a";

    became:

    div.innerHTML = toStaticHTML("   
    a");

    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)

提交回复
热议问题