YOU ARE A GENIEUS--Reed Kimble --THANK YOU SO MUCH Just a Minor Ajustment to make it work MAKE E.CANCEL = FALSE ---

I have this code whre I want to open a new window within browser1 of my form8

Instead I loose control of the browser and by loosing my session

Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow

e.Cancel = True

Form8.Show()

'Form8.WebBrowser1.Name = what goes here I am not sure what to do here

'Here I am forcing the opening of this specific website/I want to open whatever url is clicked
Form8.WebBrowser1.Navigate(
http://www.accountingonline.us/invoice/index.php page=open)

' Form8.WebBrowser1.Navigate(sender) this did not work

End Sub




Answer this question

YOU ARE A GENIEUS--Reed Kimble --THANK YOU SO MUCH Just a Minor Ajustment to make it work MAKE E.CANCEL = FALSE ---

  • Rach M

    This one was kinda tricky, but I think I've got a routine that will work for you...

    Handle the Click event of the Document, test to see if the ActiveElement is a hyperlink, if so, call navigate on the desired Browser. Here's an example snipit:

    Dim GotDocumentHandle As Boolean = False

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

    If Not GotDocumentHandle Then

    If Not Me.WebBrowser1.Document Is Nothing Then

    AddHandler WebBrowser1.Document.Click, AddressOf DocClicked

    GotDocumentHandle = True

    End If

    End If

    End Sub

    Public Sub DocClicked(ByVal sender As Object, ByVal e As HtmlElementEventArgs)

    Dim elm As HtmlElement = Me.WebBrowser1.Document.ActiveElement

    If elm.OuterHtml.ToUpper.StartsWith("<A ") Then

    Dim url As String

    url = elm.GetAttribute("href")

    Form8.WebBrowser1.Navigate(url)

    End If

    End Sub

    Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow

    e.Cancel = True

    End Sub

    That should work as desired. Test it against a few sites and see how it works out.

    GL!



  • Srdjan

    When I need to do this I have created a browswerclass. I create a new browser class and pass it the desired url. Each class has it own webbrowser control. All browser classes display and retain their sessions. I have done this in a TabControl environment so things are relatively well contained.



  • Sqnyy

    Can you show an example code

    Thanks

    I'd really like to.... but it's a very comprehensive class as it does almost everything IE does. I just cut and pasted the code and it's 23 pages long.

    Somehow, I don't think I'd win many cheers over that.



  • BrettKamerad

    Roonz,

    I think I do know what you mean - sorry so long in responding but I was out of the country last week on business.

    The problem you face is that the actual creation of the second explorer window is happening via script.

    The original question involved catching hyperlinks that spawned new windows; this was a fairly simple matter of intercepting the click of the hyperlink and then recreating is normal action with extra functionality. In your case, we could intercept the click of a submit button with ease, but that doesn't let us read or modify the script which runs as a result of clicking the submit button. I looked through the documentation for the HTMLDocument object and it does not appear to expose the scripts in the underlying page. And even if it did, I'm not sure you'd be able to modify it.

    It may take a plugin for Internet Explorer that works in conjunction with your application in order to do what you need. I can't say for sure that there's no other way to do it, but I haven't been able to think of one yet. Sorry!



  • Somsong

    anybody
  • Drksrvnt

    The solution above catches window opens and set the address for the new by looking the active element looking at the <a href tag. But what if a form is submitted and a target is to open in a new window.

    Basically what i need is;

    all new windows need to be opened in another 'form.browser' rather than a standard windows explorer window. This is because asp sessions get lost for some reason. Your method works but it only tracks hyperlinks and not others such as window.open() and form targets etc. I could use the other web browser and i catch the address by using "e.ppDisp = print.AxWebBrowser1.Application" (which doesnt work with .net browser) but if i use that i cant find a way to suppress script errors. This is a real headache.

    All i need is a web browser that will suppress script errors and load all new windows into another form which contains another browser.

    Thanks so much for your help

  • DamsDev2007

    No worries thanks for efforts. Maybe that way is too hard.

    What if i was to use the older web browser COM, I can get to work perfectly except for javascript errors. Is there a way to suppress these

  • Michael Herman - Parallelspace

    Sorry, don't know what to tell you. When I tested this with two browsers in seperate forms, my session was maintained between the two browsers.

    You might want to modify the code to also check the link for the target attribute and only redirect to the other browser when it would open a new browser.



  • byronfromwesleyan

    Can you show an example code

    Thanks



  • desilets

    That doesnt make sense using different classes. All i need is the value of where the form is spose to submit to 'action' element. How do you get that

    I think rkimble knows what i mean...


  • Ed C

    That code is fantastic!! Thanks

    But what if the window is opened from a form. I am so close to getting this working but just this last bit.

  • JDPeckham

    Sorry, could you explain a little more please I'm not sure what you mean by "window is opened from a form"...

  • GazCoder

    Thank you so much for your help !!! Reed Kimble - http://spaces.msn.com/reedkimble

    You are Hired!!!

    Fernando Pena

    HTTP://WWW.ACCOUNTINGONLINE.US


    Handle the Click event of the Document, test to see if the ActiveElement is a hyperlink, if so, call navigate on the desired Browser. Here's an example snipit:

    Dim GotDocumentHandle As Boolean = False

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

    If Not GotDocumentHandle Then

    If Not Me.WebBrowser1.Document Is Nothing Then

    AddHandler WebBrowser1.Document.Click, AddressOf DocClicked

    GotDocumentHandle = True

    End If

    End If

    End Sub

    Public Sub DocClicked(ByVal sender As Object, ByVal e As HtmlElementEventArgs)

    Dim elm As HtmlElement = Me.WebBrowser1.Document.ActiveElement

    If elm.OuterHtml.ToUpper.StartsWith("<A ") Then

    Dim url As String

    url = elm.GetAttribute("href")

    Form8.WebBrowser1.Navigate(url)

    End If

    End Sub

    Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow

    e.Cancel = True

    End Sub



  • Zulbaric

    I neglect some of the details: Here it comes

    I have a main form called Main.vb that has browser1

    I have also Form8 with browser1

    I want to have any window popup show on Form8.browser1

    I want Form8.browser1 to maintain the session

    When I log in on Main form with the browser and clic to open some url i loose the session and have to log in again within form8; I want my window popup to maintain the session.

    In my code I am opening a specific urs; i want my own browser to handle the open.window instead of the IE

    Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow

    e.Cancel = True

    'WebBrowser1.Navigate(WebBrowser1.StatusText)

    Form8.Show()

    'Form8.WebBrowser1.Name =

    ' Form8.WebBrowser1.Parent = sender

    Form8.WebBrowser1.Navigate("http://www.accountingonline.us/invoice/index.php page=open")

    ' Form8.WebBrowser1.Navigate(sender)

    End Sub



  • YOU ARE A GENIEUS--Reed Kimble --THANK YOU SO MUCH Just a Minor Ajustment to make it work MAKE E.CANCEL = FALSE ---