public class WebBrowser extends Object
On Windows, the URL is opened in the default browser by invoking the command:
rundll32 url.dll,FileProtocolHandler urlThis calling convention works on most variants of Windows, from Windows 98 to Windows 2000. It has not been tested on Windows XP.
On UNIX, this class can launch (or send a remote command to) any Netscape-compatible browser which supports the ``-remote'' switch; this includes Netscape itself, Mozilla, and possibly other browsers. An attempt is first made to open the URL in a running browser, via a command like:
netscape -remote openURL(url)and if that fails, an attempt is then made to launch the browser, via a command like:
netscape urlIn the case of an error, an exception is thrown.
On MacOS, the equivalent result can be achieved by using the method:
com.apple.mrj.MRJUtils.openURL(String url) throws IOExceptionSince this call relies on an OS-specific class library, MacOS support has not been added to this class, as doing so would break the compilation on non-MacOS systems.
Modifier and Type | Field and Description |
---|---|
private String |
browserPath |
private static String[] |
unixBrowsers |
private static String[] |
unixCommands |
private boolean |
windows |
private static String[] |
windowsBrowsers |
private static String[] |
windowsCommands |
Constructor and Description |
---|
WebBrowser()
Construct a new
WebBrowser , with no browser path specified. |
Modifier and Type | Method and Description |
---|---|
private boolean |
isWindows() |
void |
openURL(String url)
Open the specified URL in the web browser.
|
private void |
openURL(String url,
String browser,
String[] commandList) |
void |
openURL(URL url)
Open the specified URL in the web browser.
|
void |
setBrowserPath(String path)
Specify the path to a Netscape-compatible browser (such as Netscape,
Mozilla, or any other browser that supports the ``-remote'' switch).
|
private boolean windows
private String browserPath
private static final String[] unixCommands
private static final String[] unixBrowsers
private static final String[] windowsCommands
private static final String[] windowsBrowsers
public WebBrowser()
WebBrowser
, with no browser path specified.
An attempt will be made to use mozilla or netscape, in that order. It
will be assumed that a browser binary can be found in the command
search path.public void setBrowserPath(String path)
This method has no effect on Windows systems.
path
- The path to the browser.public void openURL(URL url) throws IOException
url
- The URL to open.IOException
- If the browser could not be launched.public void openURL(String url) throws IOException
url
- The URL to open.IOException
- If the browser could not be launched.private void openURL(String url, String browser, String[] commandList) throws IOException
IOException
private boolean isWindows()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses