Calling Javascript using C# WinForm
Hi.. alll
Is it possible to call a Javascript code from C# winform... If yes.. plz help me with sample codeing....
with reg
Inbaraj.d
Answers
Hi,
Do you mean Javascript on a web page? Displayed in the Web Browser control?
If you do then the WebBrowsers Document property has an InvokeScript method.
this.WebBrowser.Document.InvokeScript("foo", new string[] { "hello world" });
I have no idea how else you could do it.
Hi Inbaraj,
You can also use the "Microsoft.mshtml library" to do this.
Assume you have following JavaScript code.
Code Block<script language="javascript">
var a = 'hello';
function test(msg)
{
alert(msg);
alert(a);
}
</script>Then you can call the test function like this:
Code Blockmshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)axwebBrowser1.Document;
mshtml.IHTMLWindow2 parentWin = doc.parentWindow;
parentWin.execScript("test(99)", "javascript");
you can get detail information and sample code at:
All Replies
Hi,
Do you mean Javascript on a web page? Displayed in the Web Browser control?
If you do then the WebBrowsers Document property has an InvokeScript method.
this.WebBrowser.Document.InvokeScript("foo", new string[] { "hello world" });
I have no idea how else you could do it.
hi..
I want to call the javascript in C# windows form is it possible...
reg
Inba
Hi Inbaraj,
You can also use the "Microsoft.mshtml library" to do this.
Assume you have following JavaScript code.
Code Block<script language="javascript">
var a = 'hello';
function test(msg)
{
alert(msg);
alert(a);
}
</script>Then you can call the test function like this:
Code Blockmshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)axwebBrowser1.Document;
mshtml.IHTMLWindow2 parentWin = doc.parentWindow;
parentWin.execScript("test(99)", "javascript");
you can get detail information and sample code at:
- Hi there,
I am facing the exact scene - I need to run some js through a winform app.
If you could provide some code, because i found the link above not addressing the issue.
Thanks in advance - Jscript cannot be called from the windows forms. Why do want to do so? Is there any postbacks in windows forms?, then y do you need clien side code? Jscrip not necessarily required in windows forms.


