如何强制Web浏览器控件总是打开的网页在同一个窗口? [英] How to force Web Browser control to always open web page in the same window?

查看:179
本文介绍了如何强制Web浏览器控件总是打开的网页在同一个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Web浏览器在我的应用程序,因为它使重复任务的员工,但没有与JavaScript的一个问题,点击锚后打开IE浏览器中的一个新窗口。我如何告诉网络浏览器控制在新窗口打开,我希望它被打开?例如,在其他的网络浏览器控制?

I need to use web browser in my application as it keeps repetitive tasks from employees, but there is a problem with javascript that opens a new window in IE after clicking on anchor. How do I tell web browser control to "open new window" where I want it to be opened? For example in the other web browser control?

推荐答案

退房:的证明了概念.NET System.Windows.Forms.WebBrowser模块的使用源$ C ​​$ C

Check out: proof-of-concept of .NET System.Windows.Forms.WebBrowser module using source code

我的有关控制的经历给了我的视野,这个问题可以尝试在接下来的步骤来解决:

My experience about that controls has given me a vision that this issue can tried to be solved in next steps:

  1. 随时取消 NewWindow 事件

所有链接点击

但不是所有的链接可以被缓存这样,所以我决定来解析所有的标签&LT; A&GT; 手动<一href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted.aspx"相对=nofollow>文件加载完成

but not all link can be cached this way, so I decided to parse all tags <a> manually on Document Loading Completion

在一般情况下,这种控制是非常差,目前已经取得微软刻意。虽然有各地 Webrowser.Document.HtmlDocument功能强大的工具集和命名空间 MSHTML

in general, this control is very poor and has been made so by Microsoft deliberately. though there is powerful toolset around Webrowser.Document.HtmlDocument and namespace MSHTML

的它的使用的一个例子是的 HtmlElement.DomElement

an example of it's using is HtmlElement.DomElement

foreach(HtmlElement tag in webBrowser.Document.All)        
{
  switch (tag.TagName.ToUpper)
  {
    case "A":
    {
      tag.MouseUp += new HtmlElementEventHandler(link_MouseUp);
      break;
    }
  }
}

void link_MouseUp(object sender, HtmlElementEventArgs e)
{
  HtmlElement link = (HtmlElement)sender;
  mshtml.HTMLAnchorElementClass a = (mshtml.HTMLAnchorElementClass)link.DomElement;
  switch (e.MouseButtonsPressed)
  {
    case MouseButtons.Left:
    {
      if ((a.target != null && a.target.ToLower() == "_blank") ||
          e.ShiftKeyPressed ||
          e.MouseButtonsPressed == MouseButtons.Middle)
      {
        // add new tab
      }
      else
      {
        // open in current tab
      }
      break;
    }
    case MouseButtons.Right:
    {
      // show context menu
      break;
    }
  }
}

查看更多在第一个环节,那就是主窗口的来源$ C ​​$ C,有很多不同的手法在那里!

See more at the first link, that's the source code of main window, there are a lot of different manipulations there!

这篇关于如何强制Web浏览器控件总是打开的网页在同一个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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