使用IWebBrowser2 怎么挂接 INewWindowManager::EvaluateNewWindow?
刚开始弄浏览器开发这块,使用了IWebBrowser2,为了拦截浏览器弹窗(window.ShowModalDialog),得知INewWindowManager::EvaluateNewWindow可以做这件事,不造怎么挂接。求解答。
处理Webbrowser的NewWindow2/NewWindow3
When showModalDialog is called from script, the call is directed to the
ScriptingCallableObject.showModalDialog which in turn calls the WebBrowser
derived object CustomWebBrowser.OnShowModalDialog().
protected virtual void OnShowModalDialog(ShowModalDialogEventArgs
eventArgs)
{
eventArgs.ReturnValue = this.ShowModalDialog(eventArgs.Dialog,
eventArgs.VarArgIn, eventArgs.VarOptions);
}
private ManualResetEvent m_ModalDialogDone = null;
private bool m_isModalDialog = false;
private object m_ModalDialogVarArgIn = null;
private string m_ModalDialogVarOptions = null;
private object m_ModalDialogReturnValue = null;
internal object ShowModalDialog(string dialog, object varArgIn,
string varOptions)
{
CustomWebBrowser modalBrowser =
Program.wrapperForm.CreateNewBrowserAndTab();
modalBrowser.InitAsModalDialog(varArgIn, varOptions);
modalBrowser.Navigate(dialog);
while (!modalBrowser.m_ModalDialogDone.WaitOne(100, false)) {
try {
Application.DoEvents();
}
catch (Exception ex) {
}
}
return modalBrowser.m_ModalDialogReturnValue;
}
private void InitAsModalDialog(object varArgIn, string varOptions)
{
m_isModalDialog = true;
m_ModalDialogDone = new ManualResetEvent(false);
m_ModalDialogVarArgIn = varArgIn;
m_ModalDialogVarOptions = varOptions;
IHTMLDocument2 doc2 = this.IE.Document as IHTMLDocument2;
IHTMLWindow2 win2 = doc2.parentWindow;
win2.opener = win2;
}