如何从Process.Start打开到相同浏览器窗口或选项卡的链接? [英] How to open a link into the same browser window or tab from Process.Start?

查看:53
本文介绍了如何从Process.Start打开到相同浏览器窗口或选项卡的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Windows窗体上的LinkLabel打开浏览器窗口.单击后,控制权传递给LinkClicked事件,并且代码使用以下命令调用默认浏览器:

I am trying to open a browser window from a LinkLabel on a Windows Form. When clicked, control passes to the LinkClicked event and the code invokes the default browser using:

System.Diagnostics.Process.Start("http://www.google.com");

我希望能够单击链接(即多次运行启动"),但只能单击相同的浏览器窗口或标签.当然,多次单击每次都会为Google打开一个新标签.我知道如何使用链接指定命名窗口:

I'd like to be able to click the link (i.e. run Start multiple times) but only into the same browser window or tab. Of course, multiple clicks opens a new tab to Google each time. I know how to specify a named window using a link like:

<a href="http://www.google.com" target="googlewin">Click Here!</a>

但是我将如何在开始"命令中执行此操作?

But how would I do this in the Start command?

ETA:我在About表单上单击了Internet Explorer自己的可链接链接,并且每次都会打开一个新窗口,因此即使Microsoft也无法做到这一点.嗯.

ETA: I clicked on Internet Explorer's own linkable link on the About form, and it opens a new window each time, so perhaps not even Microsoft can do this. Hmmm.

推荐答案

对于Internet Explorer,您可以使用SHDocVw程序集来完成.

For Internet Explorer you can do this using SHDocVw assembly.

代替使用process.start只是创建SHDocVw.InternetExplorer的实例,并在需要时使用它在同一浏览器中导航.这是一个简单的例子.

Instead of using process.start just create an instance of SHDocVw.InternetExplorer and use it to navigate in same browser whenever you want. Here's a simple example.

private SHDocVw.InternetExplorer IE;

private void Form1_Load(object sender, EventArgs e)
  {
     IE = new SHDocVw.InternetExplorer();
     IE.Navigate("http://stackoverflow.com/");
     IE.Visible = true;
  }

private void button1_Click(object sender, EventArgs e)
  {
     IE.Navigate("http://google.com/");
  }

如果您特别希望使用Process.start,那么对于Internet Explorer,则可以通过SHDocVw.ShellWindows进行迭代,以找到要用于导航的Internet Explorer.

If you specifically wish to use Process.start then for internet explorer you can iterate through SHDocVw.ShellWindows to find the internet explorer you wish to use for navigating.

foreach (SHDocVw.InternetExplorer IE in new SHDocVw.ShellWindows()) {
    if (IE.FullName.ToLower.Contains("iexplore") & IE.LocationURL.ToLower.Contains("someurl")) {
        IE.Navigate("http://google.com/");
    }
}

这篇关于如何从Process.Start打开到相同浏览器窗口或选项卡的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆