当我们想禁用活动脚本时,会在IE的选项中进行设置.设置后我发现我机器上所有使用IE内核的浏览器就都禁用的活动脚本.包括我写的程序中调用的webbrowser控件.
问有没有办法在程序调用webbrowser时禁用活动脚本,而不影响包括IE自己在内的其他IE内核的程序.
问有没有办法在程序调用webbrowser时禁用活动脚本,而不影响包括IE自己在内的其他IE内核的程序.
解决方案 »
- 求vb数据库中关于删除的操作
- xp下,adodc 运行时错误91 未设置对象变量或WITH BLOCK变量
- 大哥大姐帮请我改一下,一个winsock怎么收发2个数据?
- help me!Wait for you!
- 如何使用网络打印机的自定义尺寸?
- 请高手指点为什么这个label.caption不变?
- 大家帮我估个价
- 在VB里,动态数组怎样定义?
- 用VB写的软件一定要有VB运行库支持才能正常地在别人的PC上运行吗?
- 求救:如何去掉vb窗口右上角的关闭按钮?请详细一点?
- 关于vb连接sql数据库
- win2000下水晶报表4.5复制、粘贴后,新报表的纸张大小需要重设!需要怎么解决?急急急急急急急急急急急急急急急
http://msdn.microsoft.com/workshop/browser/hosting/wbcustomization.asp
I am developing an application in Visual Basic 6.0 that hosts the WebBrowser control to display reports excerpted from Web pages. Currently, I am using WININET.DLL to download the pages, and I'm parsing them with routines I have developed. I'd like the WebBrowser control to do this so I can take advantage of Internet Explorer's robust HTML parsing, powerful DOM, and multilingual capabilities. I have implemented this functionality by placing several instances of the WebBrowser control on an invisible form. It works fine except that all images are downloaded and scripts are executed (unless, of course, I disable these capabilities on the user's computer). MSDN has just the cure for me documented for C++ in WebBrowser Customization, but I have no idea how to port this code to Visual Basic. After spending too many hours reading up on COM, I am no closer to my goal (but I am learning some of the terms I have tried for years to ignore). Can you please help me, or do I have to live with the unnecessary downloads and unexpected popup windows? Thanks in advance for any help you can give!
Bill FletcherDr. GUI replies:
Bill, the good doctor has good news and bad news. The good news is that consulting Dr. GUI demonstrates immense wisdom on your part (although perhaps mixed with a certain measure of desperation, but let's gloss over that). The bad news is that there's no way to do what you want to do directly from Microsoft® Visual Basic®. However, there is a way to do it using the Active Template Library (ATL) and C++.The technique you refer to involves implementing IDispatch on the WebBrowser's control site, and responding with the appropriate flags to disable script execution, image downloading, and page rendering. You don't have access to a Visual Basic form's implementation of IDispatch. However, you can create your own C++-based ActiveX® control that hosts the WebBrowser control, and host this container control in your Visual Basic application instead. Note This is not for the faint of heart. If you use the Active Template Library (ATL), you will need to engage in some COM somersaults, because the standard code that ATL uses for control hosting will host the control in an intermediate window (AxHostWindow, to be exact), which will prevent your container from receiving the WebBrowser's IDispatch::Invoke() calls.
After creating an ATL project, select Insert->ATL ObjectÂ…, and add an ATL Full Control. In the object's constructor, set m_bWindowOnly = TRUE to force the control to be windowed. You will then need to implement a couple of standard COM interfaces on the control: IOleClientSite and IOleInPlaceSite, the latter of which will also require you to implement IOleWindow. Many of these methods can be stubbed out (that is, made to return E_NOTIMPL), but IOleWindow::GetWindow() must be implemented in order for your host to work. Simply have it return the HWND for the container control itself as follows:STDMETHOD(GetWindow)(HWND *phwnd) {
*phwnd = m_hWnd;
return S_OK;
}Finally, implement your WM_ONCREATE event handler like this:LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
RECT rcClient;
GetClientRect(&rcClient);
// Create manually, since you don't want CAxHostWindow's IDispatch
// called, you want yours called.
CComPtr<IOleObject> spOleObject;
HRESULT hr = CoCreateInstance(CLSID_WebBrowser, NULL,
CLSCTX_INPROC, IID_IOleObject, (void**)&spOleObject);
if (hr != S_OK) {
MessageBox(_T("CoCreateInstance failed"));
return E_FAIL;
}
CComQIPtr<IOleClientSite> spSite;
spSite = this;
if (spOleObject->SetClientSite(spSite) != S_OK) {
MessageBox(_T("SetClientSite failed"));
return E_FAIL;
}
MSG msg;
hr = spOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE,
&msg, (IOleClientSite *)this, 0, m_hWnd, &rcClient);
if (hr != S_OK) {
MessageBox(_T("DoVerb failed"));
return E_FAIL;
}
m_spBrowser = spOleObject;
_ASSERT(m_spBrowser);
return SUCCEEDED(hr) ? 0 : -1;
}You're then free to implement IDispatch::Invoke() for the control and unleash your no-script-execution, no-image-downloading magic:// Handle the request for DISPID_AMBIENT_DLCONTROL for your
// ultimate Visual Basic host.
STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid, LCID lcid,
WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult,
EXCEPINFO *pexcepinfo, UINT *puArgErr) {
HRESULT hr = S_OK;
if (DISPID_AMBIENT_DLCONTROL == dispidMember) {
VariantChangeType(pvarResult, pvarResult, NULL, VT_I4);
pvarResult->lVal = DLCTL_NO_SCRIPTS | DLCTL_NO_DLACTIVEXCTLS |
DLCTL_DOWNLOADONLY | DLCTL_NO_CLIENTPULL | DLCTL_SILENT | ;
} else {
hr = DISP_E_MEMBERNOTFOUND;
}
return hr;
}If your heart is beating too fast, or you are hyperventilating, simply do what the good doctor does when he gets an urge to exercise strenuously: Lie down on a nice, soft couch and take a long nap! Good luck.