BOOL CXXXDlg::OnAmbientProperty(COleControlSite* pSite, DISPID dispid, VARIANT* pvar)
{
// TODO: 在此添加专用代码和/或调用基类
if (dispid == DISPID_AMBIENT_DLCONTROL)
{
pvar-> vt = VT_I4;
pvar-> lVal = DLCTL_NO_SCRIPTS | DLCTL_NO_JAVA
| DLCTL_NO_RUNACTIVEXCTLS | DLCTL_NO_DLACTIVEXCTLS;
return TRUE;
}
//...
}
再加上一个DLCTL_SILENT标志就可以了。
https://msdn.microsoft.com/en-us/library/aa741313(v=vs.85).aspx
DLCTL_SILENT | The browsing component will not display any user interface. This causes the BINDF_SILENTOPERATIONflag to be set when making requests through URLMON. |
BINDF enumeration
typedef enum {
BINDF_ASYNCHRONOUS = 0x00000001,
BINDF_ASYNCSTORAGE = 0x00000002,
BINDF_NOPROGRESSIVERENDERING = 0x00000004,
BINDF_OFFLINEOPERATION = 0x00000008,
BINDF_GETNEWESTVERSION = 0x00000010,
BINDF_NOWRITECACHE = 0x00000020,
BINDF_NEEDFILE = 0x00000040,
BINDF_PULLDATA = 0x00000080,
BINDF_IGNORESECURITYPROBLEM = 0x00000100,
BINDF_RESYNCHRONIZE = 0x00000200,
BINDF_HYPERLINK = 0x00000400,
BINDF_NO_UI = 0x00000800,
BINDF_SILENTOPERATION = 0x00001000,
BINDF_PRAGMA_NO_CACHE = 0x00002000,
BINDF_GETCLASSOBJECT = 0x00004000,
BINDF_RESERVED_1 = 0x00008000,
BINDF_FREE_THREADED = 0x00010000,
BINDF_DIRECT_READ = 0x00020000,
BINDF_FORMS_SUBMIT = 0x00040000,
BINDF_GETFROMCACHE_IF_NET_FAIL = 0x00080000,
BINDF_FROMURLMON = 0x00100000,
BINDF_FWD_BACK = 0x00200000,
BINDF_PREFERDEFAULTHANDLER = 0x00400000,
BINDF_ENFORCERESTRICTED = 0x00800000
} BINDF;
WebBrowser 设置 DLCTL_SILENT 启用时遇到问题
各位, 众所周知 , DLCTL_SILENT 可以被设置, 以此屏蔽 Internet Explorer Script Error 对话框 , 并且工作良好 .
但是某一日 , 我的 WebBrowser 发现 , 一定概率下 , 某些会出现 Internet Explorer Script Error 的网站 , 在被屏蔽后 , 会使整个 WB 发生无法运行js的问题. 就是说即使后来浏览别的网页, js也不起作用.
似乎别人也有类似的问题 :
http://www.tech-archive.net/Archive/InetSDK/microsoft.public.inetsdk.programming.webbrowser_ctl/2009-08/msg00023.html
当然,有解决的办法 , 你可以在 BeforeNavigate2 写下如下语句:
伪代码:
oClientCtrl = WbUnknown as IOleControl;
oClientCtrl.OnAmbientPropertyChange( DISPID_AMBIENT_DLCONTROL );
OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL); 会即时更新DISPID_AMBIENT_DLCONTROL.
加上这些代码后,目前没有出现js死亡事件.
© 2015, 新之助meow. 原创文章转载请注明: 转载自http://www.xinmeow.com