简体   繁体   English

如何在IE的当前窗口中打开-C#

[英]How to open in current window of ie - c#

I'm trying to open something in ie via 我正在尝试通过

System.Diagnostics.Process.Start("iexplore.exe", uniquePartOfUrl);

However this doesn't account for the fact a window is already open, if it is then I want to just use that. 但这并不能说明一个窗口已经打开的事实,如果是的话,我只想使用它。 How could this be done? 怎么办呢?

IMO, the best way to open a web page is to use the following syntax: IMO,打开网页的最佳方法是使用以下语法:

Process.Start("http://www.mysite.com");

This way the OS will open it in the users default browser, and use the browsers tab functionality if it has that capability. 这样,操作系统将在用户默认的浏览器中将其打开,并在具有此功能的情况下使用浏览器选项卡的功能。 Nothing annoys me more (ok, maybe some things do) than programs that force me to use a specific browser for no good reason, when I already selected which browser I want to use already. 当我已经选择了我想使用的浏览器时,没有什么比让程序无缘无故地迫使我使用特定浏览器的程序更让我烦恼(好的,也许有些事情)。 Honoring the users decision here is a good thing. 尊重用户的决定是一件好事。

On CodeProject, there exists a project to " Capturing the Running IE Instances in C# " 在CodeProject上,存在一个项目“ 捕获C#中正在运行的IE实例

It gives you one way to do it. 它为您提供了一种方法。

Using the WIN32 API, you can enumerate the windows opened, and filter them to get the running instances of IE. 使用WIN32 API,您可以枚举打开的窗口,并对其进行过滤以获取正在运行的IE实例。

It may be helpful for you. 这可能对您有帮助。

You can try something like this: 您可以尝试如下操作:

var p = new System.Diagnostics.Process();
var s = new System.Diagnostics.ProcessStartInfo(uniquePartOfUrl);
s.UseShellExecute = true;
s.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo = s;
p.Start();

I don't have a compiler handy to test it right now, but the idea is that it should simply tell the OS to "open this URL" and let the OS decide how, which may use the existing window depending on the application. 我现在没有方便的编译器来测试它,但是它的想法是,它应该简单地告诉操作系统“打开此URL”,然后让操作系统决定如何使用,取决于应用程序可以使用现有的窗口。 Worth a shot. 值得一试。

For reusing an existing window of IE, you can approach it in 2 different ways 要重用IE的现有窗口,您可以采用2种不同的方法

  1. Find the current instance of IE and then open it using that instance. 查找IE的当前实例,然后使用该实例打开它。 This is covered by the answer given by @LaGrandMere 这由@LaGrandMere给出的答案涵盖

  2. Set IE using the inbuilt settings to make it reuse itself. 使用内置设置设置IE,以使其重用。 For using this method, you can follow the instructions given at this Microsoft support article . 使用此方法,您可以按照此Microsoft支持文章中给出的说明进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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