How to open a link in a native browser from CefSharp 3

1,343 views
Skip to first unread message

Ahamed Salik

unread,
Jul 6, 2015, 4:41:01 AM7/6/15
to cefs...@googlegroups.com
I have a requirement to open a link in a native browser from CefSharp 3. I need to run the whole application in CefSharp 3's chromium browser except a form. when I click the form's link button (Eg - Register button. It has a <href> link to the registration form) I need to open this link in the native browser (Eg - Internet Explorer).

Can we achieve this in CefSharp?

Thanks in advance.
Salik

Alex Maitland

unread,
Jul 6, 2015, 5:39:35 AM7/6/15
to cefs...@googlegroups.com
Implement IRequestHandler.OnBeforeBrowser.

If the request is the one you wish to open in the default browser simply call Process.Start(url) then return true to handle the request otherwise return false to load normally.

https://github.com/cefsharp/CefSharp/blob/cefsharp/41/CefSharp/IRequestHandler.cs#L20

Basically same solution as https://github.com/cefsharp/CefSharp/issues/735#issuecomment-69352081

Ahamed Salik

unread,
Jul 6, 2015, 6:25:09 AM7/6/15
to cefs...@googlegroups.com
Hi Alex,

Thanks for the reply. I will check and get back to you.

Salik

Ahamed Salik

unread,
Jul 7, 2015, 4:59:06 AM7/7/15
to cefs...@googlegroups.com

As suggested by Alex I have implemented the OnBeforeNavigation() method in the RequestHandler class in CefSharp.Example package.

This is the working code,

 bool IRequestHandler.OnBeforeBrowse(IWebBrowser browserControl,
 IBrowser browser, IFrame frame, IRequest request, bool isRedirect)
         {
             // If the url is Google open Default browser
             if (request.Url.Equals("http://google.com/"))
             {
                 // Open Google in Default browser 
                 System.Diagnostics.Process.Start("http://google.com/");
                 return true;
             }else
             {
                 // Url except Google open in CefSharp's Chromium browser
                 return false;
             }
         }

I hope this will help to some one else in future. Thanks again Alex.

Thanks,

Salik


Reply all
Reply to author
Forward
0 new messages