MACROMEDIA DREAMWEAVER 8-DREAMWEAVER API Specifiche Pagina 143

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 692
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 142
Behaviors 143
A simple behavior example
To understand how behaviors work and how you can create one, its helpful to look at an
example. The Configuration/Behaviors/Actions folder inside the Dreamweaver application folder
contains many examples; however, many are likely to be too complex a starting point for all but
the most advanced developers. The simplest Action file to start with is Call JavaScript.htm (along
with its counterpart, Call JavaScript.js, which contains all the JavaScript functions).
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 other actions than going to URLs.
<!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 + ¬
"\')";
}else{
return "Please enter URLs in both fields."
}
}
// Extract the arguments from the function call
// in the event handler and repopulate the
// parameters form
function inspectBehavior(fnCall){
var argArray = getTokens(fnCall, "()',");
var nsURL = unescape(argArray[1]);
Vedere la pagina 142
1 2 ... 138 139 140 141 142 143 144 145 146 147 148 ... 691 692

Commenti su questo manuale

Nessun commento