• winform执行js方法


    要引用的DLL
    Interop.MSScriptControl.dll
    Interop.MSScriptControl.dll
    private void button1_Click(object sender, EventArgs e)
    {
    //js文件
    string path = AppDomain.CurrentDomain.BaseDirectory + "test.js";
    string str2 = File.ReadAllText(path);
    // 要执行的js方法名(参数)
    string fun = string.Format(@"sayHello('{0}')", this.textBox1.Text.Trim());
    string result = ExecuteScript(fun, str2);
    MessageBox.Show(result);
    }
     
    /// <summary>
    /// 执行JS
    /// </summary>
    /// <param name="sExpression">参数体</param>
    /// <param name="sCode">JavaScript代码的字符串</param>
    /// <returns></returns>
    private string ExecuteScript(string sExpression, string sCode)
    {
    MSScriptControl.ScriptControl scriptControl = new MSScriptControl.ScriptControl();
    scriptControl.UseSafeSubset = true;
    scriptControl.Language = "JScript";
    scriptControl.AddCode(sCode);
    try
    {
    string str = scriptControl.Eval(sExpression).ToString();
    return str;
    }
    catch (Exception ex)
    {
    string str = ex.Message;
    }
    return null;
    }
  • 相关阅读:
    python框架之Django(2)-简单的CRUD
    python框架之Django(1)-第一个Django项目
    实习进度13
    实习进度12
    实习进度11
    实习进度10
    学习进度08
    毕设进度07
    毕设进度06
    毕设进度05
  • 原文地址:https://www.cnblogs.com/hlei/p/6229147.html
Copyright © 2020-2023  润新知