Results 1 to 3 of 3

Thread: Webbrowser problem

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    7

    Webbrowser problem

    Hi,

    i using this code;

    vb.net Code:
    1. Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
    2.  
    3.  
    4.  
    5.             TabControl1.TabPages.Add(page)
    6.  
    7.             Select Case ToolStripComboBox1.Text
    8.                 Case "sompo"
    9.  
    10.                     sw.ScriptErrorsSuppressed = Enabled
    11.                     page.Controls.Add(sw)
    12.                     sw.Dock = DockStyle.Fill
    13.                     TabControl1.SelectedIndex = index
    14.                     index = index + 1
    15.                     UseProxy(ListBox5.Items.Item(7))
    16.                     sw.Navigate(New Uri(sompolink))
    17.  
    18.                     AddHandler sw.NewWindow, AddressOf swNewWindow
    19.                  
    20.                    
    21.                     While Not sw.ReadyState = WebBrowserReadyState.Complete
    22.                         Application.DoEvents()
    23.                     End While
    24.  
    25.                    
    26.                     Try
    27.                         sw.Document.GetElementById(sompoid).Focus()
    28.                         SendKeys.Send(ListBox5.Items.Item(5))
    29.                         System.Windows.Forms.SendKeys.Send("{TAB}")
    30.                         SendKeys.Send(ListBox5.Items.Item(6))
    31.                     Catch ex As Exception
    32.  
    33.                     End Try
    34.             End Select
    35.  
    36.     End Sub

    and i try to catch pop-up link with this code;

    vb.net Code:
    1. Private Sub swNewWindow(ByVal sender As Object, ByVal e As CancelEventArgs)
    2.  
    3. e.Cancel = True
    4.         TabControl1.TabPages.Add(page)
    5.         Dim browser As New Windows.Forms.WebBrowser()
    6.         browser.ScriptErrorsSuppressed = Enabled
    7.         page.Controls.Add(browser)
    8.         browser.Dock = DockStyle.Fill
    9.  
    10.         TabControl1.SelectedIndex = index
    11.         index = index + 1
    12.         UseProxy(ListBox5.Items.Item(7))
    13.        browser.Navigate(sw.Document.ActiveElement.GetAttribute("href"))
    14.         MsgBox(sw.Document.ActiveElement.GetAttribute("href"))
    15.  
    16. End Sub

    The problem is browser url is empty. How can i get sw.document new window link ?
    Last edited by potm; May 25th, 2018 at 06:24 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Webbrowser problem

    Please use appropriate formatting tags when posting code.

    vb.net Code:
    1. Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
    2.             TabControl1.TabPages.Add(page)
    3.  
    4.             Select Case ToolStripComboBox1.Text
    5.                 Case "sompo"
    6.  
    7.                     sw.ScriptErrorsSuppressed = Enabled
    8.                     page.Controls.Add(sw)
    9.                     sw.Dock = DockStyle.Fill
    10.                     TabControl1.SelectedIndex = index
    11.                     index = index + 1
    12.                     UseProxy(ListBox5.Items.Item(7))
    13.                     sw.Navigate(New Uri(sompolink))
    14.  
    15.                     AddHandler sw.NewWindow, AddressOf swNewWindow                  
    16.                    
    17.                     While Not sw.ReadyState = WebBrowserReadyState.Complete
    18.                         Application.DoEvents()
    19.                     End While
    20.                    
    21.                     Try
    22.                         sw.Document.GetElementById(sompoid).Focus()
    23.                         SendKeys.Send(ListBox5.Items.Item(5))
    24.                         System.Windows.Forms.SendKeys.Send("{TAB}")
    25.                         SendKeys.Send(ListBox5.Items.Item(6))
    26.                     Catch ex As Exception
    27.  
    28.                     End Try
    29.             End Select
    30.  
    31.     End Sub
    32. Private Sub swNewWindow(ByVal sender As Object, ByVal e As CancelEventArgs)
    33.  
    34.         e.Cancel = True
    35.         TabControl1.TabPages.Add(page)
    36.         Dim browser As New Windows.Forms.WebBrowser()
    37.         browser.ScriptErrorsSuppressed = Enabled
    38.         page.Controls.Add(browser)
    39.         browser.Dock = DockStyle.Fill
    40.  
    41.         TabControl1.SelectedIndex = index
    42.         index = index + 1
    43.         UseProxy(ListBox5.Items.Item(7))
    44.        browser.Navigate(sw.Document.ActiveElement.GetAttribute("href"))
    45.         MsgBox(sw.Document.ActiveElement.GetAttribute("href"))
    46.  
    47. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    7

    Re: Webbrowser problem

    Quote Originally Posted by jmcilhinney View Post
    Please use appropriate formatting tags when posting code.

    vb.net Code:
    1. Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
    2.             TabControl1.TabPages.Add(page)
    3.  
    4.             Select Case ToolStripComboBox1.Text
    5.                 Case "sompo"
    6.  
    7.                     sw.ScriptErrorsSuppressed = Enabled
    8.                     page.Controls.Add(sw)
    9.                     sw.Dock = DockStyle.Fill
    10.                     TabControl1.SelectedIndex = index
    11.                     index = index + 1
    12.                     UseProxy(ListBox5.Items.Item(7))
    13.                     sw.Navigate(New Uri(sompolink))
    14.  
    15.                     AddHandler sw.NewWindow, AddressOf swNewWindow                  
    16.                    
    17.                     While Not sw.ReadyState = WebBrowserReadyState.Complete
    18.                         Application.DoEvents()
    19.                     End While
    20.                    
    21.                     Try
    22.                         sw.Document.GetElementById(sompoid).Focus()
    23.                         SendKeys.Send(ListBox5.Items.Item(5))
    24.                         System.Windows.Forms.SendKeys.Send("{TAB}")
    25.                         SendKeys.Send(ListBox5.Items.Item(6))
    26.                     Catch ex As Exception
    27.  
    28.                     End Try
    29.             End Select
    30.  
    31.     End Sub
    32. Private Sub swNewWindow(ByVal sender As Object, ByVal e As CancelEventArgs)
    33.  
    34.         e.Cancel = True
    35.         TabControl1.TabPages.Add(page)
    36.         Dim browser As New Windows.Forms.WebBrowser()
    37.         browser.ScriptErrorsSuppressed = Enabled
    38.         page.Controls.Add(browser)
    39.         browser.Dock = DockStyle.Fill
    40.  
    41.         TabControl1.SelectedIndex = index
    42.         index = index + 1
    43.         UseProxy(ListBox5.Items.Item(7))
    44.        browser.Navigate(sw.Document.ActiveElement.GetAttribute("href"))
    45.         MsgBox(sw.Document.ActiveElement.GetAttribute("href"))
    46.  
    47. End Sub
    Sory.

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