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?
I've tried like this
Process.Start("javascript:showuser('User1');return false;");
But it is not recogniging the showuser method. Because my js file is in remote location (ex : .js)
Can you help me to do this
Thank you
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?
I've tried like this
Process.Start("javascript:showuser('User1');return false;");
But it is not recogniging the showuser method. Because my js file is in remote location (ex : http://mysite.com/userprofile.js)
Can you help me to do this
Thank you
Share Improve this question edited Jan 1, 2010 at 10:31 rahul 187k50 gold badges238 silver badges264 bronze badges asked Jan 1, 2010 at 10:25 NaguNagu 5,11414 gold badges53 silver badges70 bronze badges 1- maybe this solution can be useful – garik Commented Oct 29, 2011 at 8:39
3 Answers
Reset to default 10You 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");
You could possibly use a reference to Microsoft.JScript.dll, and something like the Evaluator
method from here; but what exactly are you trying to do? If you are wanting to script your winform, I would be tempted to use IronPython. If you want to automate a browser, you might use the WebBrowser
control.
for being able to expose COM objects you must set:
[ComVisible(true)]
outside your class (within your namespace)
something like:
namespace webform
{
[ComVisible(true)]
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
}
}