Parse JavaScript code in C#

前端 未结 4 1835
旧巷少年郎
旧巷少年郎 2021-01-18 02:00

I have the following JavaScript code as a string literal:

var $Page = new function()
{
    var _url= \'http://www.some.url.com\';

    this.Download = functi         


        
相关标签:
4条回答
  • 2021-01-18 02:22

    You could execute the javascript function using the DLR and/or MyJScript.

    0 讨论(0)
  • 2021-01-18 02:31

    You should take a look at the open-source Javascript .NET (http://javascriptdotnet.codeplex.com/) on Codeplex.

    This sample of code should help you:

    Javascript context = new JavascriptContext();
    context.Run("var _url= 'http://www.some.url.com';") // You put your javascript in the function run
    String url = (String)context.GetParameter("_url"); // You get your url from javascript
    

    That's it.

    0 讨论(0)
  • 2021-01-18 02:37

    You could use a javascript parser, but parsing javascript for just that one value is probably way overkill.

    0 讨论(0)
  • 2021-01-18 02:49

    There is an open-source JavaScript interpreter in C# at http://jint.codeplex.com, if you need more than just getting the value.

    This is now moved to GITHUB

    0 讨论(0)
提交回复
热议问题