Creating the behavior extension

The following code presents a relatively simple example. It checks the brand of the browser and goes to one page if the brand is Netscape Navigator and another if the brand is Microsoft Internet Explorer. This code can easily be expanded to check for other brands such as Opera and WebTV and modified to perform actions other than going to URLs.

To create the behavior extension:

  1. Create a new blank file.
  2. Add the following to the file:
    <!DOCTYPE HTML SYSTEM "-//Adobe//DWExtension layout-engine 5.0 ¬ //dialog"><html><head><title>behavior "Check Browser Brand"</title><meta http-equiv="Content-Type" content="text/html"><script language="JavaScript">// The function that will be inserted into the // HEAD of the user's documentfunction checkBrowserBrand(netscapeURL,explorerURL) { if (navigator.appName == "Netscape") { if (netscapeURL) location.href = netscapeURL; }else if (navigator.appName == "Microsoft Internet Explorer") { if (explorerURL) location.href = explorerURL; }}//******************* API **********************function canAcceptBehavior(){ return true;}// Return the name of the function to be inserted into// the HEAD of the user's documentfunction behaviorFunction(){ return "checkBrowserBrand";}// Create the function call that will be inserted // with the event handlerfunction applyBehavior() { var nsURL = escape(document.theForm.nsURL.value); var ieURL = escape(document.theForm.ieURL.value); if (nsURL && ieURL) { return "checkBrowserBrand(\'" + nsURL + "\',\'" + ieURL + ¬ "\')"; }else{ return "Please enter URLs in both fields." }}// Extract the arguments from the function call// in the event handler and repopulate the// parameters formfunction inspectBehavior(fnCall){ var argArray = getTokens(fnCall, "()',"); var nsURL = unescape(argArray[1]); var ieURL = unescape(argArray[2]); document.theForm.nsURL.value = nsURL; document.theForm.ieURL.value = ieURL;}//***************** LOCAL FUNCTIONS ******************// Put the pointer in the first text field// and select the contents, if anyfunction initializeUI(){ document.theForm.nsURL.focus(); document.theForm.nsURL.select();}// Let the user browse to the Navigator and// IE URLsfunction browseForURLs(whichButton){ var theURL = Adobe Dreamweaver.browseForFileURL(); if (whichButton == "nsURL"){ document.theForm.nsURL.value = theURL; }else{ document.theForm.ieURL.value = theURL; }}//*************** END OF JAVASCRIPT *****************</script></head><body><form method="post" action="" name="theForm"><table border="0" cellpadding="8"><tr><td nowrap="nowrap">&nbsp;&nbsp;Go to this URL if the browser is ¬Netscape Navigator:<br><input type="text" name="nsURL" size="50" value=""> &nbsp; <input type="button" name="nsBrowse" value="Browse..." ¬onClick="browseForURLs('nsURL')"></td></tr><tr><td nowrap="nowrap">&nbsp;&nbsp;Go to this URL is the browser is ¬Microsoft Internet Explorer:<br><input type="text" name="ieURL" size="50" value=""> &nbsp; <input type="button" name="ieBrowse" value="Browse..." ¬onClick="browseForURLs('ieURL')"></td></tr></table></form></body></html>
  3. Save the file as Configuration/Behaviors/Actions/BrowserDependentURL.htm.