vb.net2005 获取网页链接,并提示

=用按钮设置WEBBROWSER的内容================================

Private   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

 

=在Navigating获取URL===================================

   

  Private   Sub WebBrowser1_Navigating(ByVal sender As ObjectByVal 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
 

 

=在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

 

 =================方法二=========================================================

    Private   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(ByVal message As String)
        
' MessageBox.Show(message, "大家好,这是窗体程序吗?")
        Dim t As New Form1
        t.Show()
    
End Sub



 
Private   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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值