解析JavaScript的code在C#JavaScript、code

2023-09-04 22:39:40 作者:我年轻我任性

我有以下的JavaScript code作为字符串:

I have the following JavaScript code as a string literal:

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

    this.Download = function()
    {
        window.location = _url;
    }
}

有没有办法,我能得到的 _url 变量从我的C#code中的价值?一个开源库吧?我这样做是使用普通的防爆pression,但我希望有更优雅的方式。

Is there a way I could get the value of the _url variable from my C# code? An open source library perhaps? I did this using a Regular Expression, but I was hoping for a more elegant way.

推荐答案

您应该看看开源的Javascript .NET(的 HTTP://javascriptdotnet.$c$cplex.com/在codePLEX )

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

的code此示例应该帮助你:

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

就是这样。