如何让内部锚点在WebBrowser控件上工作?
这是我到目前为止所尝试的:
Private Sub Form_Load()
WebBrowser.Navigate "about:blank"
DoEvents
WebBrowser.Document.Open
WebBrowser.Document.Write "<html><head></head><body><a href=""#target"">link</a><a id=""target"" name=""target""><h1>target</h1></a></body></html>"
WebBrowser.Document.Close
End Sub
答案 0 :(得分:0)
使用js编写文档允许内部链接,但html字符串必须是javascript转义。
Private Sub Form_Load()
Dim shtml As String
WebBrowser1.Navigate2 "about:blank"
DoEvents
shtml = "<html><head></head><body><a href=""#target"">link</a><a id=""target"" name=""target""><h1>target</h1></a></body></html>"
WebBrowser1.Document.parentWindow.execScript "document.write(" & Chr(39) & shtml & Chr(39) & ")"
End Sub