views:

696

answers:

2

Hi,

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

+1  A: 

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. always cancel NewWindow event

  2. catch all links clicking

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

  4. 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

  5. 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) {
         AddTab(a.href);
         } else {
     CurrentBrowser.TryNavigate(a.href);
     }
     break;
     }
     case MouseButtons.Right: { // show context menu }
     } } }
    

See more at first link, that is source of of the main window, there are a lof of different manipulations there!

abatishchev
and How do I insert this into my application?
Skuta
dotbrowser Doesn't work with javascript, shiat
Skuta
cool, there is the URL in A but I'd need to parse it cause it's part of onclick !!! GREAT. THANK YOU
Skuta
A: 

there's an error in the case MouseBUttons.Left: Error is:Error 1 Control cannot fall through from one case label ('case 1048576:') to another C:\Documents and Settings\ever\My Documents\Visual Studio 2005\Projects\Desarrollo\wApp_SurverMonkey\wApp_SurverMonkey\frmNetcare.cs 64 17 wApp_SurverMonkey

tester