0

Relevant article: Using jQuery with Windows 8 Metro JavaScript App causes security error


Using jQuery 1.8.2 and jQuery Mobile 1.3.0

I'm currently developing a Cordova application for IOS, Android and Windows. I'm currently working on the Windows version and seems like I'm stuck with the issue where I can't add stuff through innerHtml or outerHtml.

As for an error, I'm getting this:

HTML1701: Unable to add dynamic content ' a' 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.

I've found a few solutions to this issue and the problem seems to be that Windows doesn't like you adjusting content through innerHtml or outerHtml, but wants you to do it differently.

First problem here is that I have code like the following:

$.mobile.changePage(
  "#loginPage", {
      changeHash: "false"
  }
);

Basically this will change my page to the id loginPage. The changePage will use innerHtml, thus it's not accessible for me.

A solution I tried was wrapping my code with a rule that basically says: you must know what you're doing, so I'll ignore that error for you!

MSApp.execUnsafeLocalFunction(function () {
    $.mobile.changePage(
      "#loginPage", {
          changeHash: "false"
      }
    );
});

This works, yay! Or not?
There seems to be more than 35 page changes and the application will crash on every single one of them, unless I wrap the MSApp.execUnsafeLocalFunction() around them.. But I'm not gonna do that.

Another solution that SHOULD of worked, would be adjusting the jQuery library file. Full details are explained here: Windows 8 using jquery for app development. The problem here is that it simply doesn't work. I adjusted every single rule (the assert block, the assertUsableName function and the jQuery.support function) but it just doesn't seem to work.

So for the moment, I'm out of tricks. Hope anybody can help me with this.
I'll provide more code if needed.

Community
  • 1
  • 1
Jordec
  • 1,516
  • 2
  • 22
  • 43

1 Answers1

0

Okay I figured it out myself, and it's really stupid. Alright here goes.

I did everything correct and patched the jQuery file by wrapping MSApp.execUnsafeLocalFunction() around every innerHtml inside jQuery. Since I'm using jQuery Mobile, I've also patched the jquery.mobile.js file.

The problem for me was that I was editing the wrong jquery file. Since I imported the existing project in Visual Studio, the jQuery file got added inside my /www/js/lib/jquery-mobile/, while I was looking inside /www/jquery-mobile/.

But the patches actually worked, so good for me!

Jordec
  • 1,516
  • 2
  • 22
  • 43