Menu Commands > A simple dynamic menu |
The following menu command does two things: It generates the Preview in Browser submenu, and it launches the current file (or the selected files in the Site window) in the browser that the user chooses from the submenu.
<HTML>
<HEAD>
<!-- Copyright 1999 Macromedia, Inc. All rights reserved. -->
<TITLE>Preview Browsers</TITLE>
<SCRIPT LANGUAGE="javascript">
<!--
// getDynamicContent returns the contents of a dynamically generated menu.
// returns an array of strings to be placed in the menu, with a unique
// identifier for each item separated from the menu string by a semicolon.
//
// return null from this routine to indicate that you are not adding any
// items to the menu
function getDynamicContent(itemID)
{
var browsers = null;
var PIB = null;
var i;
var j=0;
var bUpdate = dw.getMenuNeedsUpdating(itemID);
if (bUpdate)
{
browsers = new Array();
PIB = dw.getBrowserList();
// each browser pair has the name of the browser and the path that leads
// to the application on disk. We only put the names in the menus.
for (i=0; i<PIB.length; i=i+2)
{
browsers[j] = new String(PIB[i]);
if (dw.getPrimaryBrowser() == PIB[i+1])
browsers[j] += "\tF12";
if (navigator.platform == "MacPPC")
{
if (dw.getSecondaryBrowser() == PIB[i+1])
browsers[j] += "\t ?F12";
}
else
{
if (dw.getSecondaryBrowser() == PIB[i+1])
browsers[j] += "\t Ctrl+F12";
}
browsers[j] += ";id='"+PIB[i]+"'";
j = j+1;
}
dw.notifyMenuUpdated(itemID, "dw.getBrowserList()");
}
return browsers;
}
function canAcceptCommand()
{
var bHaveDocument;
if (dw.getFocus() == 'site')
bHaveDocument = site.getSelection().length > 0;
else
bHaveDocument = dw.getDocumentDOM('document') != null;
return bHaveDocument;
}
function receiveArguments()
{
var theBrowser = arguments[0];
if (dw.getFocus() == 'site')
dw.browseDocument(site.getSelection(),theBrowser);
else
dw.browseDocument(dw.getDocumentPath('document'),theBrowser);
}
// -->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>