MS Access - Web浏览器控制-如何在被点击的同一帧中打开链接文档/url



我在Microsoft Access表单中添加了一个Web浏览器控件。我让它导航到一个有附加链接的页面,我可以点击。我的问题是,当我点击一个链接时,它会在我的本地web浏览器(Edge)中打开链接。我希望新页面留在我的MS Access应用程序中,并在相同的Web浏览器控制中打开。

网站的HTML链接基本上看起来像这个<a href="#" target="_blank">打开一个新窗口(在我的情况下是一个全新的浏览器),我没有能力编辑这个网页。

有谁能给我一个解决办法吗?非常感谢!

下面是一个使用URL的基本示例,其中包含Target="_self"的链接

Private Sub UserForm_Activate()
WebBrowser1.Navigate "https://www.dofactory.com/html/target/blank"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim doc As Object, links As Object, link As Object, t

Set doc = WebBrowser1.Document
Set links = doc.getelementsbytagname("A") 'get all links

For Each link In links                      'loop over links
t = link.getAttribute("target")         'read the "target" attribute
If Not IsNull(t) Then                   'has a target ?
If t = "_blank" Then                'target is "_blank" ?
link.removeAttribute "target"   'unset the target
Debug.Print "Removed _blank"
End If
End If
Next link
End Sub

你可能在VBA语言指南中找不到任何HTML文档对象模型方法:这些方法属于"web东西"。

这是我用来获得我想要的结果的VBA代码。我确实从另一个外部渠道得到了帮助。在下面的例子中,Web浏览器控件的名称是WebBrowser0。

Dim mParentURL As String
Private Sub Form_Load()

mParentURL = Me.WebBrowser0.ControlSource
End Sub
Private Sub WebBrowser0_DocumentComplete(ByVal pDisp As Object, URL As Variant)
WebBrowser0.Object.Document.Body.innerhtml = Replace(WebBrowser0.Object.Document.Body.innerhtml, "_blank", "_self", , , vbTextCompare)
End Sub

最新更新