[Lazarus] Open URL in "default" browser X-platform
Mac Programmer
MacPgmr at fastermac.net
Thu Dec 4 01:23:16 CET 2008
Here's what I use:
{$IFDEF LINUX}
function SearchForBrowser(const BrowserFileName : string) : string;
{Search path for specified browser file name, returning
its expanded file name that includes path to it.}
begin
Result :=
SearchFileInPath(BrowserFileName, '', GetEnvironmentVariable
('PATH'),
PathSeparator, [sffDontSearchInBasePath]);
end;
function GetBrowserPath : string;
{Return path to first browser found.}
begin
Result := SearchForBrowser('firefox');
if Result = '' then
Result := SearchForBrowser('konqueror'); {KDE browser}
if Result = '' then
Result := SearchForBrowser('epiphany'); {GNOME browser}
if Result = '' then
Result := SearchForBrowser('mozilla');
if Result = '' then
Result := SearchForBrowser('opera');
end;
{$ENDIF}
You can use Shell(GetBrowserPath + ' ' + URL) although some frown on
that since Shell is deprecated, but I still use it.
With OS X, it's very easy: Shell('Open ' + URL) -- this will open
the URL in the default browser, so no need to search for it and in
fact you don't want to search for it.
Thanks.
-Phil
More information about the Lazarus
mailing list