【问题标题】:Writing embedded javascript code to c# .net [closed]将嵌入式javascript代码写入c#.net [关闭]
【发布时间】:2010-09-24 10:42:30
【问题描述】:

我有 js 文件,如何在 winform C# 中添加它, 我已经开发了前端,我想在按钮单击时运行 js 文件。 如果您提供sn-p,我将感谢您!!!! 我想以 Windows 形式运行 javascript 代码 谢谢。

【问题讨论】:

  • 对于同时涉及的 ASP.NET 和 Windows 窗体而言,完全不清楚这里发生了什么。请提供更多详细信息。
  • 你想用 javascript 做什么,导致你想从 winform 运行它?
  • “建网站”跟winforms有什么关系? winforms到底是怎么涉及的!?
  • 您需要为您的问题提供更多详细信息和上下文。使用 javascript 在 WinForms 中进行验证?不。听起来越来越像您正在构建一个 WebForms 应用程序,其中通常使用使用 javascript 的客户端验证。

标签: c# .net javascript winforms


【解决方案1】:

正如其他人在这里所说,您应该澄清您的情况。也就是说,this question 有一个关于如何从 .Net 应用程序运行 javascript 的答案。

【讨论】:

    【解决方案2】:

    您可以使用 cscript.exe 在 windows 上执行 JScript 并可以捕获标准输出的输出。

    string output;
    using (Process cscript = new Process())
    {
        // prepare the process
        cscript.StartInfo.UseShellExecute = false;
        cscript.StartInfo.CreateNoWindow = true;
        cscript.StartInfo.RedirectStandardInput = false;
        // RedirectStandardOutput should be True to get output using the StandardOutput property
        cscript.StartInfo.RedirectStandardOutput = true;
        cscript.StartInfo.FileName = "cscript.exe";
        cscript.StartInfo.Arguments = "<Path to your .js file>";
    
        cscript.Start();
        output = cscript.StandardOutput.ReadToEnd();
        cscript.Close();
    }
    

    显然你的 JScript 不能包含任何在 windows 上非法的语句

    例如,当您在浏览器中运行 JS 时,它包含窗口对象。使用 cscript.exe 在 shell 中运行 JS 时不会有 window 对象

    【讨论】:

      猜你喜欢
      • 2010-09-15
      • 2013-04-05
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多