1.WebBrowser控件如何在点击网页连接后将连接地址输出到text1中
2.当点击连接后如何屏蔽IE浏览器的弹出
VB!!!!
答案:1 悬赏:20 手机版
解决时间 2021-12-16 04:14
- 提问者网友:混世小仙女
- 2021-12-15 16:58
最佳答案
- 五星知识达人网友:爱巳過剘
- 2021-12-15 17:26
一、新建一个模块,复制下面代码:
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As PointAPI) As Long
Private Type PointAPI
x As Long
Y As Long
End Type
Function GetCurLink(Vdoc As Object) As String
Dim pt As PointAPI
Dim Ele As Object, WbHwd As Long
On Error Resume Next
GetCursorPos pt
WbHwd = WindowFromPoint(pt.x, pt.Y)
ScreenToClient WbHwd, pt
Set Ele = Vdoc.elementFromPoint(pt.x, pt.Y)
GetCurLink = Ele.href
End Function
二、调用举例:
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)
Dim S As String
S = GetCurLink(WebBrowser1.Document)
If S <> "" Then
Text1.text= S '在点击网页连接后将连接地址输出到text1中
End If
End Sub
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Cancel = True
WebBrowser1.Navigate2 WebBrowser1.Document.activeElement.href '屏蔽IE浏览器的弹出
End Sub
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As PointAPI) As Long
Private Type PointAPI
x As Long
Y As Long
End Type
Function GetCurLink(Vdoc As Object) As String
Dim pt As PointAPI
Dim Ele As Object, WbHwd As Long
On Error Resume Next
GetCursorPos pt
WbHwd = WindowFromPoint(pt.x, pt.Y)
ScreenToClient WbHwd, pt
Set Ele = Vdoc.elementFromPoint(pt.x, pt.Y)
GetCurLink = Ele.href
End Function
二、调用举例:
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)
Dim S As String
S = GetCurLink(WebBrowser1.Document)
If S <> "" Then
Text1.text= S '在点击网页连接后将连接地址输出到text1中
End If
End Sub
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Cancel = True
WebBrowser1.Navigate2 WebBrowser1.Document.activeElement.href '屏蔽IE浏览器的弹出
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯