you can implement IDocHostUIHandler::GetExternal, and access your implementation by window.external, or use a custom protocol like MyApp::SomeCommand, and handle the protocol by handling DWebBrowser2::BeforeNavigate2, or through Asynchronous Pluggable Protocol.
The cleanest way of controlling these interesting aspects of the Webbrowser control is through implementing the IDocHostUIHandler interface, but you can't find an easy way to do this in VB6. So, how do you implement it? Will the only easy way in the pre .Net days was through VC++ and there is a sample of how it can be done up on the MS Support web site ( http://support.microsoft.com/support/kb/articles/Q183/2/35.ASP), and I found some guy worked very hard to translate this sample into VB ( http://www.topxml.com/code/default.asp?p=3&id=v20031122135204). However, this method is less satisfactory: the customization can not be done before DocumentComplete, because a full DHTML Document object is needed to access its ICustomDoc interface.
The better implementations are written in native C++, usually based on MFC or ATL. One of them is the driller sample ( http://msdn.microsoft.com/archive/en-us/samples/internet/browser/driller/default.asp), and the other is the MFC 8.0 implementation, while MFC 7.0 and 7.1 are buggy.
In .Net 1.0 and 1.1, you can implement the IDocHostUIHandler interface much easier (http://www.codeproject.com/csharp/advhost.asp), however, the implementation of the .Net wrapper of the WebBrowser control is almost unknown, so ICustomDoc is also required.
In .Net 2.0 (still in beta), the new WinForm WebBrowser control is much better, and is almost the same of the MFC 8.0 implementation. However, its implementation details are still almost unknown, but it would satisfy most of WebBrowser developers.
NTAddLink.html 文件:
<script language = "VBScript">
'Download selected link
sub AddLink(Url, Remark)
On Error Resume Next
set NTIECatcher = CreateObject("NTIEHelper.NTIEAddUrl")
if err = 0 then
call NTIECatcher.AddLink(external.menuArguments.document.Url, Url, Remark)
end if
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)