Discussion:
Showing URL in default browser
Darius Blaszijk
2006-02-21 23:40:28 UTC
Permalink
What could be considered as a platform independent way to show an URL in the default browser? Under windows it would be something like:

ShellExecute(0, 'open', MyURL, nil, nil, SW_SHOW);

But it relies on the windows unit. I believe that Lazarus relies on the definition of the browser executable and launching it with the URL as parameter. Is this the way to go?

Darius
Mattias Gaertner
2006-02-21 23:58:08 UTC
Permalink
On Wed, 22 Feb 2006 00:40:28 +0100
Post by Darius Blaszijk
What could be considered as a platform independent way to show an URL in
ShellExecute(0, 'open', MyURL, nil, nil, SW_SHOW);
But it relies on the windows unit. I believe that Lazarus relies on the
definition of the browser executable and launching it with the URL as
parameter. Is this the way to go?
It would be nice, if someone would write a package with a component to start
a browser. Preferably without opening a new page/tab on every call.
I added examples/openbrowser/.
Maybe you want to add the above command for windows.

Mattias
Felipe Monteiro de Carvalho
2006-02-22 00:32:45 UTC
Permalink
Post by Mattias Gaertner
It would be nice, if someone would write a package with a component to start
a browser. Preferably without opening a new page/tab on every call.
I added examples/openbrowser/.
Maybe you want to add the above command for windows.
This problem is very hard to solve on Unix. I can´t imagine a solution
that isn´t Desktop-specific or browser-specific.

Currently on Virtual Magnifying Glass I simply call mozilla-firefox to
open the page on linux and do a ShellExecute on Windows. Even then, on
some distros the firefox executable has a different name =/

I´m not saying it can´t be done, but I´m raising some difficulties and
asking for ideas on how to solve them =)
--
Felipe Monteiro de Carvalho
L505
2006-02-22 01:07:51 UTC
Permalink
Post by Felipe Monteiro de Carvalho
Post by Mattias Gaertner
It would be nice, if someone would write a package with a component to start
a browser. Preferably without opening a new page/tab on every call.
I added examples/openbrowser/.
Maybe you want to add the above command for windows.
This problem is very hard to solve on Unix. I can´t imagine a solution
that isn´t Desktop-specific or browser-specific.
Currently on Virtual Magnifying Glass I simply call mozilla-firefox to
open the page on linux and do a ShellExecute on Windows. Even then, on
some distros the firefox executable has a different name =/
I´m not saying it can´t be done, but I´m raising some difficulties and
asking for ideas on how to solve them =)
Where's the the Lin32 API when you need it? (Ermm. good quote of the year)

Does firefox have some sort of API that allows users to remote control it from
another process? Does *NIX itself offer any standard inter-process communication
tactic or must each program contain a home brewed custom server damon (written
from scratch each time) to receive unix sockets or other API/remote
communication?
Felipe Monteiro de Carvalho
2006-02-22 01:48:02 UTC
Permalink
Post by L505
Where's the the Lin32 API when you need it? (Ermm. good quote of the year)
Lol! Like people say here. It doesn't exist yet, but fell free to
implement it. rssss
Post by L505
Does firefox have some sort of API that allows users to remote control it from
another process? Does *NIX itself offer any standard inter-process communication
tactic or must each program contain a home brewed custom server damon (written
from scratch each time) to receive unix sockets or other API/remote
communication?
You don't need a Firefox API to do this. Just send the shell command:
"mozilla-firefox www.google.com" and if firefox is already open, it
will open the page without opening a new instance. I tested here, try
on your command line with firefox already open. If you want it to open
a new instance, there is probably a command line switch for this.

--
Felipe Monteiro de Carvalho
Mattias Gaertner
2006-02-22 01:55:54 UTC
Permalink
On Tue, 21 Feb 2006 22:48:02 -0300
Post by Felipe Monteiro de Carvalho
Post by L505
Where's the the Lin32 API when you need it? (Ermm. good quote of the year)
Lol! Like people say here. It doesn't exist yet, but fell free to
implement it. rssss
Post by L505
Does firefox have some sort of API that allows users to remote control
it from another process? Does *NIX itself offer any standard
inter-process communication tactic or must each program contain a home
brewed custom server damon (written from scratch each time) to receive
unix sockets or other API/remote communication?
"mozilla-firefox www.google.com" and if firefox is already open, it
will open the page without opening a new instance. I tested here, try
on your command line with firefox already open. If you want it to open
a new instance, there is probably a command line switch for this.
See examples/openbrowser/ how to do that with mozilla, galeon, firefox,
konqueror, netscape and opera.


Mattias
A.J. Venter
2006-02-22 05:28:34 UTC
Permalink
Post by Mattias Gaertner
Post by Felipe Monteiro de Carvalho
"mozilla-firefox www.google.com" and if firefox is already open, it
will open the page without opening a new instance. I tested here, try
on your command line with firefox already open. If you want it to open
a new instance, there is probably a command line switch for this.
See examples/openbrowser/ how to do that with mozilla, galeon, firefox,
konqueror, netscape and opera.
Actually I find users PREFER having browser calls open in tabs, if they
already have a copy of firefox open, they usually do not want to end up with
another instance (once people get used to tabs, they fall in love with them,
I know I did).

Here is the way I handled browsing in OpenBook btw. you may edit/use if it
suits you:
Helper := '';
{$IFDEF Linux}
if shell('which opera') = 0 then
Helper := 'opera';
if shell('which mozilla') = 0 then
Helper := 'mozilla';
if shell('which konqueror') = 0 then
Helper := 'konqueror';
if shell('which firefox') = 0 then
Helper := 'firefox';
{$ENDIF}
If Helper = '' then
Begin
LocateFRM.Label2.Caption := 'a web browser';
LocateFRM.ShowModal;
If LocateFRM.ModalResult = MrOK then
Helper := LocateFRM.Locator.Text else
begin
ShowMessage('Error: Install a web browser !');
Application.Terminate;
end;
end;
Config.Add('BROWSER='+Helper);

-----
As you can see I check for the existence of opera, mozilla, konqueror and
firefox in that order, e.g. if both konqueror and firefox are in the user's
path then firefox will win, if none of these are there, I show a dialog
allowing the user to select his own browser command.
I use a similar function to get a PDF viewer as wel.

A.J.
--
A.J. Venter
Chief Software Architect
OpenLab International
www.getopenlab.com
www.silentcoder.co.za
+27 82 726 5103
Patrick Chevalley
2006-02-22 08:54:57 UTC
Permalink
I think it is nice to first try to launch the default application defined in
KDE or GNOME, this not necessarily Konqueror or Galeon.
To do that use "kfmclient exec" or "gnome-open".
This work not only for url but also for any mime type. For example launch
Xpdf or Acroread as defined in the desktop preference for a pdf file.

Patrick
Bram Kuijvenhoven
2006-02-22 09:32:52 UTC
Permalink
Post by Felipe Monteiro de Carvalho
"mozilla-firefox www.google.com" and if firefox is already open, it
will open the page without opening a new instance. I tested here, try
on your command line with firefox already open. If you want it to open
a new instance, there is probably a command line switch for this.
Note that FireFox has an option under Tools -> Options ... -> Tabs about what to do when 'links are opened from other applications': new window, new tab in most recent window, or most recent window/tab. (But as far as I know, FireFox does not start a separate process.)

Personally I favor the first two options above the last one, as I don't like the webpage I'm visiting to disappear suddenly because it is replaced by a page opened by some app. On the other hand, if the app is opening pages occasionally -- like the help function in Lazarus -- it would be nice if the app would have a 'private' window/tab it can reuse time over time (perhaps identified by some ID code on the command line). I'm afraid this isn't possible with the current FireFox, and that in fact an internal html viewer or embedded browser would be more suitable for such a job.

Regards,

Bram

Loading...