locked
Is it possible to call managed Code from external Javascript?

    Question

  • Hello,

    i have a Windows Phone 8.1 program which downloads Html and Javascript Files from a Server. Those Javascript Files should be able to call managed Code (C#), because they need access to native methods and things like Text to Speech.

    Now i wonder if it is possible to build a Bridge from Javascript to C#?

    In Android an equivalent would be the @JavascriptInterface Annotation.

    Monday, September 22, 2014 2:00 PM

Answers

  • Why not just parse the HTML in c# and run the TTS from there?  If you're modifying the JS on the server, you could add comments the c# app could read and interpret.

    Darin R.

    • Marked as answer by B.Ke Tuesday, September 23, 2014 7:03 AM
    Monday, September 22, 2014 7:39 PM

All replies

  • No, and this would be a serious security hole.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, September 22, 2014 7:05 PM
    Moderator
  • Why not just parse the HTML in c# and run the TTS from there?  If you're modifying the JS on the server, you could add comments the c# app could read and interpret.

    Darin R.

    • Marked as answer by B.Ke Tuesday, September 23, 2014 7:03 AM
    Monday, September 22, 2014 7:39 PM
  • It is only a security issue when it could contain untrusted content. The Application doesn't contain untrusted content and only Users with access to the server can upload Files. The Server is of course as save as it can be,

    Last but not least the Javascript File wouldn't have access to the whole Application. Only to Methods which are declared with @JavascriptInterface Annotation. Those Methods are hardcoded so you can't change anything with it. Even less security issues i could imagine right now,

    but good point anyway. Time to think about Darins answer! I think it is a good idea.

    Problem is that i can't trigger any Method via Button Click. 

    • Edited by B.Ke Tuesday, September 23, 2014 12:24 PM
    Tuesday, September 23, 2014 7:03 AM