DonCorleone
DonCorleone

Reputation: 31

GeckoFX hyperlink with target='_blank' in browser

I need a hyperlink with target='_blank' from geckowebbrowser1 to open in geckowebbrowser2 and not in a new window.

        private void geckowebbrowser1_CreateWindow(object sender, GeckoCreateWindowEventArgs e)
    {
        geckowebbrowser2.Navigate(e.Uri);

    }

but a new window is created anyway :(

Upvotes: 0

Views: 541

Answers (1)

Timo Salomäki
Timo Salomäki

Reputation: 7189

Looking at the source code, you could avoid creation of the new window by setting Cancel to false, like this:

private void geckowebbrowser1_CreateWindow(object sender, GeckoCreateWindowEventArgs e)
{
    e.Cancel = true;
    geckowebbrowser2.Navigate(e.Uri);
}

If you're interested, here's the part of the source code that handles the creation of a new window and calling the CreateWindow event handler:

GeckoWebBrowser browser = parent as GeckoWebBrowser;
if (browser != null)
{
    var e = new GeckoCreateWindowEventArgs(flags);
    browser.OnCreateWindow(e);

    if (e.Cancel)
    {
        cancel = true;
        return null; // When you set cancel to true on your end, the below code for creating a new window won't run
    }

    if (e.WebBrowser != null)
    {
        // set flags
        ((nsIWebBrowserChrome) e.WebBrowser).SetChromeFlagsAttribute(chromeFlags);
        return e.WebBrowser;
    }

    nsIXULWindow xulChild = AppShellService.CreateTopLevelWindow(null, null, chromeFlags, e.InitialWidth, e.InitialHeight);
    return Xpcom.QueryInterface<nsIWebBrowserChrome>(xulChild);
}

return null;

Upvotes: 1

Related Questions