解析JavaScript的code在C# [英] Parse JavaScript code in C#

查看:147
本文介绍了解析JavaScript的code在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的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

就是这样。

这篇关于解析JavaScript的code在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆