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 "-//Macromedia//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 document
function 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 document
function behaviorFunction(){
return "checkBrowserBrand";
}
// Create the function call that will be inserted
// with the event handler
function applyBehavior() {
var nsURL = escape(document.theForm.nsURL.value);
var ieURL = escape(document.theForm.ieURL.value);
if (nsURL && ieURL) {
return "checkBrowserBrand(\'" + nsURL + "\',\'" + ieURL + ¬
308
Behaviors
Need help?
Do you have a question about the DREAMWEAVER 8-EXTENDING DREAMWEAVER and is the answer not in the manual?
Questions and answers