User Guide

A dynamic menu 169
// Only launch the browser if we have a valid browser selected
if (theBrowser != "file:///" && typeof(theBrowser) != "undefined" &&
theBrowser.length > 0)
{
if (dw.getFocus(true) == 'site')
{
// Only get the first item of the selection because
// browseDocument() can't take an array.
//dw.browseDocument(site.getSelection()[0],theBrowser);
site.browseDocument(theBrowser);
}
else
dw.browseDocument(dw.getDocumentPath('document'),theBrowser);
}
else
{
// otherwise, if the user hit the F12 or Ctrl+F12 keys,
// ask if they want to specify a primary or secondary browser now.
if (whichBrowser == 'primary')
{
result = window.confirm(MSG_NoPrimaryBrowserDefined);
}
else if (whichBrowser == 'secondary')
{
result = window.confirm(MSG_NoSecondaryBrowserDefined);
}
// If they clicked OK, show the prefs dialog with the browser panel
if (result)
dw.showPreferencesDialog('browsers');
}
}
}
The function first sets the variable whichBrowser to the value that Dreamweaver passes,
arguments[0]. Along with setting other default values, the function also sets return to a default
value of
false.
After initializing variables, the
receiveArguments() function calls the user-defined function
havePreviewTarget() and tests the result. If the result of the test is true, the function checks to
see if the user selected the primary or secondary browser. If so, the function sets the variable
theBrowser to the path of the executable file that starts the browser (dw.getPrimaryBrowser()
or dw.getSecondaryBrowser()). The function then performs a loop that examines the list of
browsers returned by
dw.getBrowsersList(). If the path to a browser in the list matches the
path to the primary or secondary browser, the function sets the variable theBrowser to the
matching value in
browserList. This value contains the name of the browser and the path to the
executable file that starts the browser. If
havePreviewTarget() returns the value false, the
function sets the variable theBrowser to the value of the variable whichBrowser.
Next, the
receiveArguments() function tests the variable theBrowser to make sure that it does
not begin with a path, that it is not "undefined", and that it has a length greater than zero. If all
these conditions are true, and if the Site panel has focus, the
receiveArguments() function calls
the
site.browseDocument() function to invoke the selected browser with the files selected in
the Site panel. If the Site panel does not have focus, the receiveArguments() function calls the
function
dw.browseDocument() and passes it the path of the current document and the value
of the variable
theBrowser, which specifies the name of the browser with which to open
the document.