Option Explicit
Private Sub Form_Load()
WebBrowser1.Navigate "STARTING PAGE"
End Sub
Private Sub Form_Resize()
'
Text1.Move 10, 0, Me.Width - 150
WebBrowser1.Move 10, Text1.Top + Text1.Height, Me.Width - 150, (Me.Height - WebBrowser1.Top)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
'
If KeyAscii = vbKeyReturn Then
' see if ".com" is in the Text1.text field
If InStr(Text1.Text, ".com") Then
' if so then pass it to the WebBrowser1 control
WebBrowser1.Navigate Text1.Text
Else
' if not, toss it at the end of the google string
' and search google for the Text1.text
WebBrowser1.Navigate "http://www.google.com/search?q=" & Text1.Text
End If
KeyAscii = 0 ' clear KeyCode so you dont get a beep
' Comment out that line and you will hear a beep when the 'enter'
' is pressed.
End If
End Sub
Private Sub webBrowse_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
'txtURL.Text = URL 'Additionally you can use this, but it shows all child URL's too (such as URL's loaded in iFrames)
txtURL.Text = WebBrowser1.Document.URL
txtURL.SelStart = 0
txtURL.SelLength = Len(txtURL.Text)
End Sub
' Cancel any navigation that moves outside VB helper.
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As _
Object, URL As Variant, Flags As Variant, _
TargetFrameName As Variant, PostData As Variant, _
Headers As Variant, Cancel As Boolean)
Const TARGET = "about:blank"""
Cancel = (LCase$(Left$(URL, Len(TARGET))) <> TARGET)
If Cancel Then MsgBox URL & " is blocked"
End Sub
' Don't let the user open a new window.
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel _
As Boolean)
Cancel = True
MsgBox "You cannot open a new window."
End Sub