Re: Runtime.exec for launching browser windows: location-independent?



In article <J-ednQisBMnHwQXenZ2dnUVZ_sudnZ2d@xxxxxxx>,
"Mickey Segal" <not_monitored@xxxxxxxxxxx> wrote:

> As the "pure Java" way of launching new browser windows, the showDocument
> method, is rendered nonfunctional in more and more environments by popup
> blockers, developers whose Java applets are digitally-signed have been able
> to get the same functionality by using Runtime.exec calls.
>
> On the Macintosh one can open a new Firefox window regardless of the
> location of Firefox as follows:
>
> Runtime.getRuntime().exec(new String[] {"open", "-a", "Firefox.app",
> url.toString()});
>
> On Windows it is possible to launch Internet Explorer or Firefox by assuming
> a particular location as follows:
>
> Runtime.getRuntime().exec("\"C:\\Program Files\\Internet
> Explorer\\IEXPLORE.EXE\" " + url);
> Runtime.getRuntime().exec("\"C:\\Program Files\\Mozilla
> Firefox\\firefox.exe\" \"" + url + "\"");
>
> The problem is that these forms depend on the browser files being in their
> usual locations. Is there a way of launching the browsers in a
> location-independent way using Java code on Windows, by analogy to what
> works on the Macintosh even if Firefox is not in its usual location in the
> /Applications folder?
>
>
> NOTE: We use new browser windows to display further information on outside
> Web sites such as articles about a diagnosis being considered by the user.
> Using a new browser window allows us to do so without destroying our applet
> or trying to shoehorn someone else's Web page into a frame on the same page
> as our applet.

On a Mac, you can omit the "-a" switch to the "open" command and allow
the system to use the preferred browser. By default, that's Safari on
all recent systems, but it can of course be changed. I have mine set
for Firefox, and it's in a non-standard location, but that approach
works perfectly in my testing. It also works for files, provided the
system has a setting for the application to handle the file.

On Windows systems beyond 98 (we dropped support in our app for 98 and
earlier, including NT), you can use "cmd start url" to hand off the URL
to the designated default browser. The same approach seems to work for
files if there's an association for them. I believe I recall that it
resulted in prompting when no associated application was found (and
perhaps for Mac OS X as well). I haven't tried in Windows 98, but the
"cmd.exe" used to be "command.com" and may well work there too. Aside
from renaming the command interpreter, I don't know how much else has
changed down deep.

Even on Linux, I found that an approach could be used that depends on
information about the desktop environment being used. That's more
tricky to do, but it's clearly possible since any given environment
(like KDE, Gnome, etc.) has some kind of file manager program that can
show files and allow one to be opened with a designated application.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
.


Quantcast