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.