2

I'm developing an application for Windows Phone 8.

Basically the application is developed using jQuery/jquery Mobile, Javascript and HTML and I want to add content dynamically.

Whenever I try to do this an error occurs which is:

0x800c001c - JavaScript runtime error: Unable to add dynamic content. 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 searched for it and found that you cannot add HTML content dynamically due to security reasons. I also found that we can forcefully do that within the function:

MSApp.execUnsafeLocalFunction(function () {});

But the problem is, in the whole application I've to add HTML content Dynamically. So there will be extra overhead for any small content adding to be written with the function.

The HTML content i want to add is for example:

var Html = '<div class="boxgrid2 cover" style="background-image: url(images/' + varimage + '), url(images/BoxTrade.png);" ><div id="qty1" class="AniQty1 allfont">' + quantity + '</div><div id="name1" class="AniName1 allfont">' + varaname + '</div><div id="rate1" class="AniRate1 allfont">' + buyrate1 + '</div></div>';
$("#tradeAnimalDiv").html(Html);

So basically the content contains div's and dynamic contents that are fetched from local database.

If there is any other solution or setting which can be used to allow permission for dynamically adding HTML content than please help me out.

Thanks & Regards

Rishi
  • 330
  • 2
  • 13
  • Could you provide a sample of the content you are trying to add to the DOM? – Romain Oct 04 '12 at 07:32
  • @Romain Edited the question with the content that i want to add. – Rishi Oct 04 '12 at 07:41
  • 2
    You should probably take a look at http://stackoverflow.com/questions/10859523/using-jquery-with-windows-8-metro-javascript-app-causes-security-error – Romain Oct 04 '12 at 07:51
  • Windows Phone don't use JavaScript as a application language. The OP is still embedded it inside a browser. – Claus Jørgensen Oct 04 '12 at 21:23
  • 1
    @ClausJørgensen Thanks for your comment. Basically I've developed game using HTML5, jQuery/jQuery Mobile and I want to implement it in Windows Phone 8. Everything else is going fine except that when i add some HTMl content Dynamically the error occurs as stated in the question. – Rishi Oct 05 '12 at 05:43
  • Have not seen such issue on WP8/jQMobile/Ajax dynamic content. @Rishi, could you please confirm the issue exists on Windows Phone 8 and not in Windows 8. – Sergei Grebnov Oct 12 '12 at 18:34
  • @SergeiGrebnov: I tried to create a project with blank javascript template in VS2012. In that I just included my already running iphone/android application's file and all the references were perfectly given. While running the application in Simulator/Local Machine Error occured as stated in the question. I'm using jquery 1.7.1, jqmobile 1.1.0. – Rishi Oct 13 '12 at 09:36
  • I have voted up the question because I'm having the same issue and I still don't find a straightforward way to deal with it. If I have to type MSApp.execUnsafeLocalFunction before thousands of lines of code I will simply drop the WP8 version of my App for good. – andreszs Aug 14 '16 at 21:14

0 Answers0