locked
Universal Javascript app errors RRS feed

  • Question

  • I am making a relatively simple windows 10 app with html and JavaScript. I got almost everything working but when I try to load one of my pages I get lots of errors and my onclick event doesn t work anymore.

    DOM7011: The code on this page disabled back and forward caching. For more information

    HTML1506: Unexpected token.
    MainDishes.html (392,6)

    CSP14312: Resource violated directive script-src ms-appx: unsafe-eval in Host Defined Policy: inline script. Resource will be blocked.


    I am using an onclick event to go to the top of the page that no longer works. I know i can't have any inline script but i don't think i do. All my script is in a separate file. what do i do???

    This is the html that doesn't work. if you need more information just tell me.

    https://onedrive.live.com/redir?resid=F1148B29E7D33207!117916&authkey=!APj66LgUSy3zZeE&ithint=file%2ctxt

    Saturday, September 26, 2015 6:32 PM

Answers

  • Hello Coeus89,

    I looked at the html page. the code below

      <a target="_self" href="/MainDishes/POLENTA.html" class="pageFetcher" onclick="goToTop()">
                    <img src="/MainDishes/Polenta.jpg" alt="Polenta">
                  </a>

    Did you try adding onclick event using JavaScript instead of the inline html? I Tested in UWP and inline onclick does not work Instead you can use getElementsByClassName function.

    	var elements = document.getElementsByClassName('pageFetcher');
    	for (var i = 0; i < elements.length; i++) {
    	elements[i].addEventListener('click', goToTop, false);
    	}
    				

    Or Alternatively you can follow Prashant's suggestion here to make it work with your current HTML and inline JavaScript

    https://social.msdn.microsoft.com/Forums/en-US/c1a8ee65-90fd-4e2d-b16c-8cad74937905/uwphtmlhow-to-set-csp-in-wua-to-access-a-js-api-which-is-marked-unsafeeval?forum=wpdevelop#c1a8ee65-90fd-4e2d-b16c-8cad74937905

    Hope this helps.

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 28, 2015 5:55 AM