Using jQuery 1.8.1 for Windows 8 Javascript Metro App

If you use jQuery for Windows 8 Javascript Metro App, you may encounter the following error when you run the app:

“HTML1701: Unable to add dynamic content ‘ a’ A script attempted to inject dynamic content, or elements previously modified dynamically, that might be unsafe.”

To avoid this error, you need to edit the offending .js file (e.g. jquery-1.8.1.js).  In other words, you don’t use the minified version.  Also, you cannot use the online CDN version, you must include the jquery-xxxxx.js in your project.

The key is to wrap around the offending lines of code with “MSApp.execUnsafeLocalFunction”.  For example,

MSApp.execUnsafeLocalFunction(function () {
div.innerHTML = "<a name='" + expando + "'></a><div name='" + expando + "'></div>";
});

or you can even wrap around the whole function.  For example,

jQuery.support = MSApp.execUnsafeLocalFunction(function() {

var support,
all,
a,
select,
opt,
input,
fragment,
eventName,
i,
isSupported,
clickFn,
div = document.createElement("div");

// blah blah blah

return support;
});

Reference Article

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s