Results 1 to 4 of 4

Thread: Page not loading e.cancel = true

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    48

    Page not loading e.cancel = true

    Why would this not work? I get the new window to open yet it does not load. When I right click to veiw source it is empty.
    It will load without this in IE.
    The Address looks normal

    http://v.XXX.com/XXX/nVia7OaEHd7UYlv4.html

    Code:
    Private Sub WebBrowser2_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser2.NewWindow
    
            Dim myElement As HtmlElement = WebBrowser1.Document.ActiveElement
            Dim target As String = myElement.GetAttribute("href")
    
            Dim newInstance As New Form5
            newInstance.Show()
            newInstance.WebBrowser1.Navigate(target)
            'cancel opening IE window
            e.Cancel = True
        End Sub
    Thank You
    Last edited by Norseman; Mar 22nd, 2012 at 02:59 AM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Page not loading e.cancel = true

    check your target... make sure the url is correct.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Page not loading e.cancel = true

    This is how I have handled the NewWindow. Set a reference to Microsoft Internet Controls on the COM tab of the Add Reference Dialog and use code similar to this:
    Code:
      Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("http://www.vbforums.com")
        Dim activeXBrowser As SHDocVw.WebBrowser = CType(WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser)
        AddHandler activeXBrowser.NewWindow3, AddressOf axBrowserNewWindow3
      End Sub
    
      Private Sub axBrowserNewWindow3(ByRef ppDisp As Object, ByRef cancel As Boolean, dwflags As UInteger, bstrUrlContent As String, bstrUrl As String)
        Dim frm As New Form1
        frm.Show()
        frm.WebBrowser1.Navigate(bstrUrl)
        cancel = True
      End Sub
    
      Private Sub WebBrowser1_NewWindow(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
        e.Cancel = True
      End Sub

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    48

    Re: Page not loading e.cancel = true

    Joacim

    That worked I get this error though. Can I put it in try command to control that? Or how? I do not have any private declarations also on Netframe 4.

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Private Sub Form14_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    WebBrowser2.Navigate("http://api.v.xxxx.com/xxxxx/sports/live.html")
    Dim activeXBrowser As SHDocVw.WebBrowser = CType(WebBrowser2.ActiveXInstance, SHDocVw.WebBrowser)
    AddHandler activeXBrowser.NewWindow3, AddressOf axBrowserNewWindow3
    End Sub

    Private Sub axBrowserNewWindow3(ByRef ppDisp As Object, ByRef cancel As Boolean, ByVal dwflags As UInteger, ByVal bstrUrlContent As String, ByVal bstrUrl As String)
    Dim frm As New Form5
    frm.Show()
    frm.WebBrowser1.Navigate(bstrUrl)
    cancel = True
    End Sub

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

    End Class
    Last edited by Norseman; Mar 22nd, 2012 at 10:06 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width