如何单击默认浏览器中打开的铬浏览器链接? [英] How make a click on a chromium browser link open in the default browser?

查看:102
本文介绍了如何单击默认浏览器中打开的铬浏览器链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现以下目的:当用户单击TChromium浏览器页面内的超链接时,新页面将在其默认浏览器中打开。

I want to achieve that when a user clicks on a hyperlink inside a TChromium browser page, the new page opens in his default browser.

推荐答案

OnBeforeBrowse 事件检查 navType 参数是否等于 NAVTYPE_LINKCLICKED ,如果是,则将True返回到 Result 参数(将取消对Chromium的请求)并调用例如 ShellExecute 传递 request.Url 值以在用户的​​默认浏览器中打开链接:

In the OnBeforeBrowse event check if the navType parameter equals to NAVTYPE_LINKCLICKED and if so, return True to the Result parameter (which will cancel the request for Chromium) and call e.g. ShellExecute passing the request.Url value to open the link in the user's default browser:

uses
  ShellAPI, ceflib;

procedure TForm1.Chromium1BeforeBrowse(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest;
  navType: TCefHandlerNavtype; isRedirect: boolean; out Result: Boolean);
begin
  if navType = NAVTYPE_LINKCLICKED then
  begin
    Result := True;
    ShellExecuteW(0, nil, PWideChar(request.Url), nil, nil, SW_SHOWNORMAL);
  end;
end;

这篇关于如何单击默认浏览器中打开的铬浏览器链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆