I have problem with awesomium web control 1.7.4 in WPF , when the user click links in page , awesomium navigate to targetURL , but i want to open that links in system default browser.

also I want to determine mailto:jondue@example.com to open this links in default Email client.

Please help me.

Thanks

Update :

I've been doing some more searching to solve my problem, after few days I founded that when the link has a target=_blank the event ShowCreatedWebView is fired. The main problem was about links without target=_blank. After that I'm able to find links without that cause firing event RequestBringIntoView.

private void Browser_ShowCreatedWebView(object sender, Awesomium.Core.ShowCreatedWebViewEventArgs e)
    {
        System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
    }

and

private void Browser_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
    {
        if (Browser.TargetURL != new Uri("about:blank"))
        {
            System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
            e.Handled = true;
        }
    }
有帮助吗?

解决方案

I've been doing some more searching to solve my problem, after few days I founded that when the link has a target=_blank the event ShowCreatedWebView is fired. The main problem was about links without target=_blank. After that I'm able to find links without that cause firing event RequestBringIntoView.

private void Browser_ShowCreatedWebView(object sender, Awesomium.Core.ShowCreatedWebViewEventArgs e)
{
    System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
}

and

private void Browser_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
    if (Browser.TargetURL != new Uri("about:blank"))
    {
        System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
        e.Handled = true;
    }
}

其他提示

You could try using IResourceInterceptor to decide what you want to do when Awesomium loads a page.

public partial class MainWindow : Window
{
    public MainWindow()
    {
        WebCore.Initialize(new WebConfig());
        WebCore.Initialized += ((object sender, CoreStartEventArgs e) =>
        {
            WebCore.ResourceInterceptor = new ResourceInterceptor("http://google.com/");
        });

        InitializeComponent();
    }
}


public class ResourceInterceptor : IResourceInterceptor
{
    //Url of the first page to be loaded inside webcontrol without redirection.
    protected string m_startupURL;

    public ResourceInterceptor(string startupURL)
    {
        m_startupURL = startupURL;
    }

    public virtual bool OnFilterNavigation(NavigationRequest request)
    {
        if (request.Url.ToString() != m_startupURL)
        {
            System.Diagnostics.Process.Start(request.Url.ToString());
            return true;
        }

        return false;
    }

    public ResourceResponse OnRequest(ResourceRequest request)
    {
        return ResourceResponse.Create(request.Url.OriginalString);
    }
}

This is a very basic implementation. You should add some additional tests on the Url. Actually Process.Start(request.Url.ToString()) can do anything (launching an application or formatting your disk). So don't forget to test whether it is a valid Url or a mailto: link.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top