ADC Home > Reference Library > Technical Q&As > Networking > Internet & Web >

Launching the Default Internet Browser


Q: My code needs to launch the default Internet browser to open my ".html" help files. What is the best way to do this?

A: Mac OS 8.5 introduced the Internet control panel which, among other things, can be used to select and configure the preferred web browser. This Internet control panel is based on the popular Internet Config API, which is used (and in the case of earlier Mac OS versions, sometimes installed) by many of the third-party applications such as Internet Explorer, Anarchie, and Eudora.

Information about the Internet control panel can be found in the Mac OS 8.5 Technote.

Documentation on Internet Config and methods to detect its presence can be found at the Internet Config web site.

In addition to maintaining a database of user preferences, the Internet Config API also provide a way to programatically invoke the default browser and request that it opens a specified URL. This is illustrated in the following code snippet:

#include <Types.h>
#include <InternetConfig.h>
OSStatus LaunchURL(ConstStr255Param urlStr)
{
    OSStatus err;
    ICInstance inst;
    long startSel;
    long endSel;
    err = ICStart(&inst, '????');           // Use your creator code if you have one!
    if (err == noErr) {
        err = ICFindConfigFile(inst, 0, nil);
        if (err == noErr) {
                startSel = 0;
                endSel = urlStr[0];
                err = ICLaunchURL(inst, "\p", (char *) &urlStr[1],
                        urlStr[0], &startSel, &endSel);
            }
        (void) ICStop(inst);
    }
    return (err);
}

Example 1: Using Internet Config to Launch an URL

There are a few things you should do if you wish to redirect the launch of HTML documents to the user's preferred web browser when they are double-clicked in the Finder.

  1. Set the files creator code 'udog'. In the some version of Mac OS (8.0 - 8.5.1) this will cause the scripting addition "Apple Browser Launcher" to be invoked. On these systems, double-clicking on HTML file with 'udog' creator will direct the Finder to launch the Browser Launcher script. Browser Launcher then looks up the user's preferred web browser in Internet Config, which invokes the browser to open the HTML document in a manner similar to the above snippet.
  2. Append a ".html" to your file names. In later versions of the Mac OS this will assist the "File Exchange" Control Panel (assuming that it is enabled and properly configured) to redirect the opening of your HTML document to the default browser.

In addition, you might also want to investigate the HTML-rendering services provided by the help system introduced in Mac OS 9. See Inside Macintosh: HTML Rendering Library Reference for more information.

[Oct 11 1999]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.