C# 如何打开替代的网络浏览器(Mozilla 或 Firefox)并显示特定的 url?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/223268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I open alternative webbrowser (Mozilla or Firefox) and show the specific url?
提问by Skuta
I know there is built-in Internet explorer, but what I'm looking for is to open Firefox/Mozilla window (run the application) with specified URL. Anyone can tell me how to do that in C# (.nET) ?
我知道有内置的 Internet Explorer,但我正在寻找的是使用指定的 URL 打开 Firefox/Mozilla 窗口(运行应用程序)。任何人都可以告诉我如何在 C# (.nET) 中做到这一点?
采纳答案by Hallgrim
This will launch the system defined default browser:
这将启动系统定义的默认浏览器:
string url = "http://stackoverflow.com/";
System.Diagnostics.Process.Start(url);
Remember that Process.Start(url) might throw exceptions if the browser is not configured correctly.
请记住,如果浏览器配置不正确,Process.Start(url) 可能会抛出异常。
回答by Austin Salonen
Use the Process class (System.Diagnostics) using the URL as the process name. This will use the system default browser to open the URL. If you specify a browser, you run the risk that the browser doesn't exist.
使用进程类 (System.Diagnostics),将 URL 作为进程名称。这将使用系统默认浏览器打开 URL。如果您指定浏览器,则会冒浏览器不存在的风险。
回答by Ilya Ryzhenkov
See ProcessInfo.UseShellExecute
请参阅 ProcessInfo.UseShellExecute
回答by Guy
In Visual Studio click the File -> Browse With... on the menus and then select the browser that you want to use. You can also change the browser there. If the Browse With... menu option doesn't appear then you need to select a project from your solution that that can be launched in a browser.
在 Visual Studio 中,单击菜单上的文件 -> 浏览方式...,然后选择要使用的浏览器。您也可以在那里更改浏览器。如果 Browse With... 菜单选项没有出现,那么您需要从您的解决方案中选择一个可以在浏览器中启动的项目。
回答by Tom Ritter
If you explicitly do not want to use the User's default browser, you can run the browser with the URL as the first argument.
如果您明确不想使用用户的默认浏览器,您可以使用 URL 作为第一个参数运行浏览器。
C:\Program Files\Mozilla Firefox>firefox.exe http://google.com
C:\Program Files\Mozilla Firefox>firefox.exe http://google.com
launches Firefox with google for me. But as people have said, you run the risk of it not being installed, or being installed to a different place, etc.
为我启动带有谷歌的 Firefox。但是正如人们所说,您冒着未安装或安装到其他地方等的风险。
回答by Bruno Le Duic
You can do this:
你可以这样做:
System.Diagnostics.Process.Start("firefox.exe", "http://www.google.com");