Articles Archive
Articles Search
Director Wiki
 

Opening a Specific Browser

July 3, 2002
by Will Turnage

Hello Handyman,

I wonder if you can help me? It's only a minor problem. When I make an external link to a website using behaviours my project automatically launches Netscape Navigator. Is there any specific Lingo that tells director which web browser to launch?

Cheers,
Phil

Dear Phil,

In the world of Lingo, the default browser used by Director to open web pages is controlled through the browserName function. The browserName function is a little different than most other Lingo functions, because there are three different ways you can use it.

The first way to use browserName is to not pass any parameters to it. In this case, the function returns Director's current default browser.

put browserName()
-- "C:\Program Files\Internet Explorer\iexplore.exe"

The next use for browserName is if you actually pass it a file path to a web browser. If you do this, then Director will reset its default browser path with whatever path you specify. For instance,

browserName ("C:\Program Files\Netscape\Netscape 6\netscp6.exe")
put browserName()
-- "C:\Program Files\Netscape\Netscape 6\netscp6.exe"

The last way to use the browserName function is to specify whether the automatic launching of web browsers is enabled. For instance,

browserName (#enabled, true)

will have a browser automatically launch when you execute a goToNetPage command. However, if you say:

browserName (#enabled, false)

then Director would not launch a browser automatically. This function is helpful if you want to create a CD-ROM that has the power to work in an online and offline mode.

But to answer your question, all you need to set the default browser in your Director movies is a path to a valid browser. You can get the path to a browser using one of many system Xtras available, like the free FileXtra3, DirectOS Xtra, or BuddyAPI. In these examples, though, you'll use the free FileXtra3.

If you wanted to set your default browser when your movie begins, you could use the following code:

on prepareMovie

  fileObj = new (xtra "FileXtra3")
  if the platform contains "Windows" then
    systemBrowser = fileObj.FileGetAppPath (".html")
  else
    systemBrowser = fileObj.FileGetAppPath ("HTMLMSIE")
  end if
  fileObj = 0
  browserName (systemBrowser)
  browserName (#enabled, true)

end

This handler begins by creating a new instance of FileXtra3 Xtra. Next, it checks to see if you're running on Windows or Mac. If you're running on Windows, then it gets the system's default application for files ending in .html. If you're running on the Mac, then it gets the default path for files with a type and creator of HTMLMSIE which in this case is for Internet Explorer. If you wanted to default to Netscape automatically on the Mac, then you could use this line of code instead:

  systemBrowser = fileObj.FileGetAppPath ("HTMLMOSS")

Once you have the full path to your browser, then you delete your instance of the FileXtra3 by setting it to zero.

Next, you set the browserName equal to the default browser on your system, and you end the handler by activating the browserName so that web pages will open automatically.

Another great use of the browserName function is the ability to offer users the option to select their own default browser. This is easily done using the following handler.

on setCustomBrowser

  fileObj = new (xtra "fileXtra3")
  if the platform contains "Windows" then
    newBrowser = fileObj.fx_FileOpenDialog (the moviePath, "", "Select a custom browser...", FALSE, TRUE)
  else
    newBrowser = fileObj.fx_FileOpenDialog (the moviePath, "")
  end if
  fileObj = 0
  if newBrowser <> EMPTY then
     browserName (newBrowser)
    browserName (#enabled, true)
  end if

end

This handler starts by creating a new instance of the FileXtra3. Next, it checks to see if you're running on Mac or Windows, and depending on the platform, it displays a dialog box allowing the user to choose the browser they want to use. Once the user has made a selection, then you delete your instance of the FileXtra3 by setting it to zero. Next, you check to make sure that the new browser name is not empty (meaning the user didn't hit the Cancel button and there were no errors), and if so, then you set the browserName to be the browser selected by the user.

If you put the setCustomBrowser function in one of your movie scripts, then all you have to do is create a behavior on your Change Default Browser button that contains this code.

on mouseUp me

  setCustomBrowser ()

end

And that's all there is to it. Have fun coding!

All colorized Lingo code samples have been processed by Dave Mennenoh's brilliant HTMLingo Xtra, available from his site at http://www.crackconspiracy.com/~davem/

Will Turnage is a multimedia programmer based in New York City. In addition to his weekly role as Director Online's Multimedia Handyman, he is also the Technology Director for Sony Music's Client Side Technologies Group. You can read more about his work at http://will.turnage.com/.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.