是否有可能调用从C#的WinForms Javascript方法?

问题描述:

我有一个JavaScript文件,它包含的一些方法。我想打电话从我的WinForm应用程序的方法。是否可以?如果是的话你能不能给我一个简单的例子?

I've a JavaScript file and it contains some methods. I want to call those methods from my winform application. Is it possible? If so can you give me a simple example?

我已经试过像这样

的Process.Start( 的javascript:showuser('用户1');返回false;);

Process.Start("javascript:showuser('User1');return false;");

但它不是recogniging的showuser方法。因为我的js文件是在远程位置
(例如: http://mysite.com/userprofile.js

But it is not recogniging the showuser method. Because my js file is in remote location (ex : http://mysite.com/userprofile.js)

你能帮我做到这一点。

感谢您

您可以使用的 web浏览器控制。下面是一个示例帖子

You could use a WebBrowser control. Here's a sample post.

webBrowser1.DocumentText = 
    @"<html><head>
      <script type='text/javascript'>
      function testFunction() {
          alert('test');
      }
      </script>
      </head><body></body></html>";
webBrowser1.Document.InvokeScript("testFunction");