示例#1
0
        void _browser_StartNewWindow(object sender, BrowserExtendedNavigatingEventArgs e)
        {
            frmWebBrowser mf = GetMainFormFromControl(sender as Control);

            if (mf == null)
            {
                return;
            }

            // Allow a popup when there is no information available or when the Ctrl key is pressed
            bool allowPopup = (e.NavigationContext == UrlContext.None) || ((e.NavigationContext & UrlContext.OverrideKey) == UrlContext.OverrideKey);

            if (!allowPopup)
            {
                // Give None, Low & Medium still a chance.
                switch (SettingsHelper.Current.FilterLevel)
                {
                case PopupBlockerFilterLevel.None:
                    allowPopup = true;
                    break;

                case PopupBlockerFilterLevel.Low:
                    // See if this is a secure site
                    if (this.WebBrowser.EncryptionLevel != WebBrowserEncryptionLevel.Insecure)
                    {
                        allowPopup = true;
                    }
                    else
                    {
                        // Not a secure site, handle this like the medium filter
                        goto case PopupBlockerFilterLevel.Medium;
                    }
                    break;

                case PopupBlockerFilterLevel.Medium:
                    // This is the most dificult one.
                    // Only when the user first inited and the new window is user inited
                    if ((e.NavigationContext & UrlContext.UserFirstInited) == UrlContext.UserFirstInited && (e.NavigationContext & UrlContext.UserInited) == UrlContext.UserInited)
                    {
                        allowPopup = true;
                    }
                    break;
                }
            }
            // Check wheter it's a HTML dialog box. If so, allow the popup but do not open a new tab
            if (!((e.NavigationContext & UrlContext.HtmlDialog) == UrlContext.HtmlDialog))
            {
                if (!e.Url.ToString().Contains("/index.jsp"))
                {
                    Global.sysConfig.WindowConfig.Url       = e.Url.AbsoluteUri.ToString();
                    Global.sysConfig.WindowConfig.Viewmodel = mf.sViewModel;
                    frmWebBrowser m = new frmWebBrowser(Global.sysConfig.GetSetting());
                    e.AutomationObject = m.getAutomationObject();
                    m.Show();
                    e.Cancel = true;
                }
                else
                {
                    this.WebBrowser.Navigate(e.Url.ToString());
                    e.Cancel = true;
                }
            }
            else
            {
                // Here you could notify the user that the pop-up was blocked
                e.Cancel = true;
            }
        }