我想实现这一点,当用户单击 TChromium 浏览器页面内的超链接时,新页面会在他的默认浏览器中打开。
问问题
1978 次
2 回答
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;
于 2014-09-03T09:38:36.133 回答
4
在 CEF3navType = 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;
于 2017-05-19T03:58:51.237 回答