=用按钮设置WEBBROWSER的内容================================
Private
Sub Button1_Click()
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = _
"<html><body>Please enter your name:<br/>" & _
"<input type='text' name='userName'/><br/>" & _
"<a href='http://www.microsoft.com' name='t'>continue</a>" & _
"</body></html>"
s = "<a href='http://www.163.com' >aaaaaaaaaaa</a><br><a href=""#b"">bbbbbbbbbbbb</a><br><a href=""http://www.baidu.com"" >百度</a><br>"
'Me.WebBrowser1.Navigate("http://localhost/z.asp")
WebBrowser1.DocumentText = s
End Sub
Dim s As String = _
"<html><body>Please enter your name:<br/>" & _
"<input type='text' name='userName'/><br/>" & _
"<a href='http://www.microsoft.com' name='t'>continue</a>" & _
"</body></html>"
s = "<a href='http://www.163.com' >aaaaaaaaaaa</a><br><a href=""#b"">bbbbbbbbbbbb</a><br><a href=""http://www.baidu.com"" >百度</a><br>"
'Me.WebBrowser1.Navigate("http://localhost/z.asp")
WebBrowser1.DocumentText = s
End Sub
=在Navigating获取URL===================================
Private
Sub WebBrowser1_Navigating()
Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
Dim document As System.Windows.Forms.HtmlDocument = WebBrowser1.Document
If e.Url.ToString.IndexOf("baidu") >= 1 Then
e.Cancel = True
MsgBox("baidu域名")
Dim s As New Form2
s.Show()
End If
If e.Url.ToString.IndexOf("163") >= 1 Then
e.Cancel = True
MsgBox("163域名")
End If
If e.Url.ToString.IndexOf("#b") >= 1 Then
e.Cancel = True
MsgBox("自定义链接")
End If
' If document IsNot Nothing And document.All("userName") IsNot Nothing And _
' String.IsNullOrEmpty(document.All("userName").GetAttribute("value")) Then
' e.Cancel = True
' MsgBox("You must enter your name before you can navigate to " & e.Url.ToString())
' End If
End Sub
Dim document As System.Windows.Forms.HtmlDocument = WebBrowser1.Document
If e.Url.ToString.IndexOf("baidu") >= 1 Then
e.Cancel = True
MsgBox("baidu域名")
Dim s As New Form2
s.Show()
End If
If e.Url.ToString.IndexOf("163") >= 1 Then
e.Cancel = True
MsgBox("163域名")
End If
If e.Url.ToString.IndexOf("#b") >= 1 Then
e.Cancel = True
MsgBox("自定义链接")
End If
' If document IsNot Nothing And document.All("userName") IsNot Nothing And _
' String.IsNullOrEmpty(document.All("userName").GetAttribute("value")) Then
' e.Cancel = True
' MsgBox("You must enter your name before you can navigate to " & e.Url.ToString())
' End If
End Sub
=在WebBrowser1_NewWindow防止用户使用SHIFT跳出新窗口======================================
Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
e.Cancel = True
End Sub
e.Cancel = True
End Sub
=================方法二=========================================================
Private
Sub Button1_Click()
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Me.WebBrowser1.Navigate("http://localhost/z.asp")
WebBrowser1.AllowWebBrowserDrop = False
WebBrowser1.IsWebBrowserContextMenuEnabled = False
WebBrowser1.WebBrowserShortcutsEnabled = False
WebBrowser1.ObjectForScripting = Me
' 只有在完成调试后才将ScriptErrorsSuppressed属性设定成True。
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.DocumentText = _
"<html><head><script>" & _
"function sayhi(message) { alert(message); }" & _
"</script></head><body><a href=""#"" target=_blank οnclick=""window.external.SayHello('这是在 Script 指令代码中调用窗体 SayHello 程序')"">程序链接</a></html>"
End Sub
Public Sub SayHello() Sub SayHello(ByVal message As String)
' MessageBox.Show(message, "大家好,这是窗体程序吗?")
Dim t As New Form1
t.Show()
End Sub
Private Sub Button3_Click() Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Document.InvokeScript("sayhi", _
New String() {"这是在窗体程序代码中调用 Script 函数 SayHi"})
End Sub
' Me.WebBrowser1.Navigate("http://localhost/z.asp")
WebBrowser1.AllowWebBrowserDrop = False
WebBrowser1.IsWebBrowserContextMenuEnabled = False
WebBrowser1.WebBrowserShortcutsEnabled = False
WebBrowser1.ObjectForScripting = Me
' 只有在完成调试后才将ScriptErrorsSuppressed属性设定成True。
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.DocumentText = _
"<html><head><script>" & _
"function sayhi(message) { alert(message); }" & _
"</script></head><body><a href=""#"" target=_blank οnclick=""window.external.SayHello('这是在 Script 指令代码中调用窗体 SayHello 程序')"">程序链接</a></html>"
End Sub
Public Sub SayHello() Sub SayHello(ByVal message As String)
' MessageBox.Show(message, "大家好,这是窗体程序吗?")
Dim t As New Form1
t.Show()
End Sub
Private Sub Button3_Click() Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Document.InvokeScript("sayhi", _
New String() {"这是在窗体程序代码中调用 Script 函数 SayHi"})
End Sub