locked
Windows 8 grid app. innerHTML error please help!!!URGENT

    Question

  • Hello,

    Yesterday I was writing my app in javascript, i was adding content by creating variables with text inside, and then, i just put the variables in the sampleItems( content). I had already created 5 variables and then when I ran the app, and clicked in a itemDetail the app crashes and this error shows up :

    Exception is about to be caught by JavaScript library code at line 14, column 13 in ms-appx://eecc34aa-13d8-4386-8c55-3b25c5fd39ef/pages/itemDetail/itemDetail.js

    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.

    If there is a handler for this exception, the program may be safely continued.

    Am I doing something wrong?

    How can i solve this?

    Please, HELP ME

    thanks,

    Sunday, January 27, 2013 6:46 PM

Answers

  • Hi Shurtugalsc,

    As other member mentioned, it would be helpful if you can show some of the code you used in your windows store app that might cause the error.

    According to the error message and your descrption, you're programmtically assign some text to the innerHTML property of some html elements of the app pages, correct? If this is the case, I'd suggest you try using the "MSApp.execUnsafeLocalFunction" function to wrap the code (which will inject dynamic content via innerHTML). e.g.

    MSApp.execUnsafeLocalFunction(function() {
      var div = document.getElementsByTagName('div')[0];
      div.innerHTML = '<div>dynamic div element</div>';
    });


    here is the MSDN reference which mentioned details about this:


    #execUnsafeLocalFunction method (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/Hh767331.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Monday, February 04, 2013 2:26 AM
    Monday, January 28, 2013 6:14 AM
    Moderator

All replies

  • Without seeing your code it is almost impossible to assist you.  Post the code where it is crashing.

    Monday, January 28, 2013 1:55 AM
  • Hi Shurtugalsc,

    As other member mentioned, it would be helpful if you can show some of the code you used in your windows store app that might cause the error.

    According to the error message and your descrption, you're programmtically assign some text to the innerHTML property of some html elements of the app pages, correct? If this is the case, I'd suggest you try using the "MSApp.execUnsafeLocalFunction" function to wrap the code (which will inject dynamic content via innerHTML). e.g.

    MSApp.execUnsafeLocalFunction(function() {
      var div = document.getElementsByTagName('div')[0];
      div.innerHTML = '<div>dynamic div element</div>';
    });


    here is the MSDN reference which mentioned details about this:


    #execUnsafeLocalFunction method (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/Hh767331.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Monday, February 04, 2013 2:26 AM
    Monday, January 28, 2013 6:14 AM
    Moderator