当前位置: 首页 > 编程语言 > C#

如何使用C#启动具有特定url的GoogleChrome选项卡Share

时间:2023-04-10 17:32:33 C#

如何使用C#启动具有特定url的GoogleChrome选项卡在GoogleChrome中,并在自定义应用程序中加载特定的URL?我的应用程序是用C#(.NET4Full)编码的。我在C#中通过SOAP执行一些操作,一旦成功完成,我想通过浏览器将最终结果呈现给用户。整个设置是针对我们的内部网络,而不是供公众使用——所以,我只能针对特定的浏览器。由于各种原因,我只针对Chrome。作为chrfin响应的简化,由于Chrome应该安装在运行路径上,您可以调用:Process.Start("chrome.exe","http://www.YourUrl.com");这似乎对我有用,如果Chrome已经打开,则会打开一个新选项卡。//在默认浏览器中打开Process.Start("http://www.stackoverflow.net");//在InternetExplorer中打开Process.Start("iexplore",@"http://www.stackoverflow.net/");//在Firefox中打开Process.Start("firefox",@"http://www.stackoverflow.net/");//在GoogleChrome中打开Process.Start("chrome",@"http://www.stackoverflow.net/");更新:请参阅Dylan或dc的答案以获得更简单(更稳定)的解决方案,该解决方案不依赖于安装Chrome的LocalAppData!即使我同意DanielHilgarth关于在chrome中打开新选项卡的观点,您也只需要以URL作为参数执行chrome.exe:Process.Start(@"%AppData%..LocalGoogleChromeApplicationchrome.exe","http:\www.YourUrl.com");如果用户没有Chrome,会抛出如下异常:以上是C#学习教程:HowtouseC#tostartaGoogleChrometabwithaspecificURLtosharingallthecontent,如果对大家有用的话和需要了解更多关于C#学习教程,希望大家多多关注—//chrome.exehttp://xxx.xxx.xxx--incognito//chrome.exehttp://xxx.xxx.xxx-incognito//chrome.exe--隐身http://xxx.xxx.xxx//chrome.exe-incognitohttp://xxx.xxx.xxxprivatestaticvoidChrome(stringlink){stringurl="";如果(!string.IsNullOrEmpty(链接))//如果为空就运行浏览器{if(link.Contains('.'))//检查它是一个url还是一个google搜索{url=link;}else{url="https://www.google.com/search?q="+link.Replace("","+");}}try{Process.Start("chrome.exe",url+"--incognito");}catch(System.ComponentModel.Win32Exceptione){MessageBox.Show("无法找到GoogleChrome...","chrome.exenotfound!",MessageBoxButtons.OK,MessageBoxIcon.Error);}}本文收集自网络,不代表立场。侵权请点击维权联系管理员删除如需转载请注明出处: