简体   繁体   中英

Launch javascript code in a browser

I am doing an add-in for Outlook (C#) I created a button in the Ribbon. When I click on the button I want to automatically open a browser with url and then launch a javascript javascript:Goto(); in the code behind. Is this possible?

If the javascript is just a part of the page opened, yes, that is possible. You can open the URL with Process.Start . It will open the default browser (so from there you have little control over the execution):

Process.Start(@"http://somewebsite.sample");

Another option is the use of the WebBrowser control in c#. You can execute custom javascript in it too. You can use WebBrowser.InvokeScript for that. You need to place that on a Form inside your application.

this.webBrowser.Navigate("http://somewebsite.sample")
this.webBrowser.InvokeScript("SomeGotoMethod", new object[] { "somevariable" });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM