我想实现这一点,当用户点击TChromium浏览器页面内的超链接时,新页面将在其默认浏览器中打开。
答案 0 :(得分:4)
在OnBeforeBrowse
事件中检查navType
参数是否等于NAVTYPE_LINKCLICKED
,如果是,则返回True到Result
参数(这将取消Chromium的请求)并呼吁例如ShellExecute
传递request.Url
值以打开用户默认浏览器中的链接:
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;
答案 1 :(得分:2)
在CEF3中,navType = NAVTYPE_LINKCLICKED
事件中不再可能OnBeforeBrowse
,就像在TLama的答案中一样。相反,我发现了如何使用TransitionType
属性...
procedure TfrmEditor.BrowserBeforeBrowse(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; isRedirect: Boolean; out Result: Boolean);
begin
case Request.TransitionType of
TT_LINK: begin
// User clicked on link, launch URL...
ShellExecuteW(0, nil, PWideChar(Request.Url), nil, nil, SW_SHOWNORMAL);
Result:= True;
end;
TT_EXPLICIT: begin
// Source is some other "explicit" navigation action such as creating a new
// browser or using the LoadURL function. This is also the default value
// for navigations where the actual type is unknown. Do nothing.
end;
end;
end;