Question click on java script link

bnnoor

Member
Joined
Jun 29, 2011
Messages
6
Programming Experience
Beginner
hi all freinds:

i have a problem witm my app . my app click on first link on page an go to page but in javascript link new link open in new ie explore and exit on my app :(
but i want new link open in my browser on webbrowser1
any one can help me?
 
What you want can't be done simply with the .NET WebBrowser control. You need to handle an event that is not exposed by the managed control, so you need to get its ActiveXInstance cast it as an ActiveX web browser and then handle its (I think) NewWindow2 event.
 
Here's the code to get access to the event:
Public Class Form1

    Private WithEvents axWebBrowser As AxSHDocVw.AxWebBrowser

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.axWebBrowser = DirectCast(Me.WebBrowser1.ActiveXInstance, AxSHDocVw.AxWebBrowser)
    End Sub

    Private Sub axWebBrowser_NewWindow2(sender As Object, e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles axWebBrowser.NewWindow2
        '...
    End Sub

End Class
I've never actually done it myself so I'm not 100% sure how to specify the window in which to open the new page but I think that it goes like this: create a new WebBrowser control or get an existing one, get it's ActiveXInstance property and assign that to e.ppDisp field in the event handler. You may also have to set the RegisterAsBrowser property of that instance to True, although it may already by default.
 
I should also point out that you will need the appropriate reference added to your project for that to work. You can either add a reference to Microsoft Internet Controls from the COM tab or you can temporarily add an ActiveX web browser control to your form.
 
I should also point out that you will need the appropriate reference added to your project for that to work. You can either add a reference to Microsoft Internet Controls from the COM tab or you can temporarily add an ActiveX web browser control to your form.

thanks. but i dont know your means . this direct is to confused . can you insert an example project?

create a new WebBrowser control or get an existing one, get it's ActiveXInstance property and assign that to e.ppDisp field in the event handler. You may also have to set the RegisterAsBrowser property of that instance to True

???????
 
but its very hard to control new widow ( control like webbrowswer1 ) because only relantion is one handle and i cant copy anything to new page or close it :(
 
Back
Top