Código HTML:
// Connect to the X10 Commander server by opening a window.
// The AJAX method should be preferred.
function windowMethod(url, closeIt) {
if (closeIt) {
var w = window.open(url, "X10Window",
"dependent,height=1,width=1,location=no,menubar=no,scrollbars=no,status=no,toolbar=no");
// Immediately close the window.
w.close();
}
else {
window.open(url, "X10Window",
"dependent,height=100,width=100,location=yes,menubar=no,scrollbars=no,status=yes,toolbar=no");
}
}
// Connect to the X10 Commander server via AJAX.
function ajaxMethod(url) {
try {
// Send HTTP GET without opening a window.
var request = new XMLHttpRequest();
request.open("GET", url, true, serverID, serverPassword);
request.send(null);
}
catch (e) {
// Request threw an exception. This does not necessarily mean it failed.
var err = e; // bring error into scope so it can be examined in debugger
if (allowErrorAlert) {
// Show the error message.
var errString;
if (typeof(err) == "string") {
errString = err;
}
else {
errString = err.toString();
if (errString == null || errString == "" || errString == "[object Error]")
errString = err.name + ": " + err.message;
}
if (err.message.match(/Access is denied/))
// Probably an IE security error.
errString += "\nMake sure the server " + location.hostname +
" is in your local intranet or other trusted zone.";
else if (err.message.match(/Security violation/))
// Probably an Opera security error.
errString +=
"\n\nSet \"useAjax\" to \"false\" in the Web X10der script source code \
because it will always fail with your browser (probably Opera).";
alert(errString);
}
if (allowFallback)
// Revert to using a browser window to send the command.
windowMethod(url, true);
}
}
// Turn a device on or off, or brighten or dim it.
function setDevice(deviceNum, state, transmitMethod) {
// if (debug) alert("setDevice(" + deviceNum + ", " + state + ", " + transmitMethod + ");");
// Do not change the 8086 or the funny characters in the url string.
// X10 Commander server requires them as is.
var url = "http://" + server + ":8086/?x10command=DEVICE~send" +
transmitMethod + "~\"" + devices[deviceNum] + " " + state + "\"";
// Kludge: append timestamp to URL to force IE to open it every time.
// Other browsers don't seem to need this.
var today = new Date;
url += "&time=" + today.getTime();
if (debug)
// Open a window, leaving it open to show the command sent and the response received.
windowMethod(url, false);
else if (useAjax)
// Use the AJAX method.
ajaxMethod(url);
else
// Use the window.open() method.
windowMethod(url, true);
if (showStatus)
window.status = devices[deviceNum+1] + " set to " + state + " via " +
transmitMethod.toUpperCase();
}
// Function to generate the HTML for the page full of buttons.
function generate() {
var s; // string accumulator
// Write some text.
if (myHeading != null && myHeading != "") document.writeln("<h1 style='color:red;position:relative;left:100px;top:0px;'>" + myHeading + "</h1>");
if (showServer) document.writeln("<h5>Server: " + server + "</h5>");
// Write a table, one row per X10 device.
document.writeln("<table>");
for (var i = 0; devices[i] != "END"; i += 4) {
var lcMethod, ucMethod; // lowercase & uppercase transmission methods
if (devices[i+3] == RF) { lcMethod = "\"rf\""; ucMethod = "RF"; }
else { lcMethod = "\"plc\""; ucMethod = "PLC"; }
// Show the device name.
document.write("<tr><td>" + devices[i+1] + "</td>");
// Show the device address if user wants to see it.
if (showCodes)
document.write("<td>(" + devices[i] + " " + ucMethod + ")</td>");
// Add Off , On Buttons
s = "<td><button type='button' style='background-color: #cc0000; color: #ffffff;'";
if (showHovertext) s += " title='" + devices[i] + " OFF " + ucMethod + "'";
s += " onClick='setDevice(" + i + ", \"OFF\", " + lcMethod +
");'> Off </button></td>"
document.write(s);
s = "<td><button type='button' style='background-color: #00cc00; color: #000000;'";
if (showHovertext) s += " title='" + devices[i] + " ON " + ucMethod + "'";
s += " onClick='setDevice(" + i + ", \"ON\", " + lcMethod +
");'> On </button></td>"
document.write(s);
// If device is dimmable...
if (devices[i+2] == DIM) {
// ... add Dim button...
s = "<td><button type='button'";
if (showHovertext)
s += "title='" + devices[i] + " DIM " + dimPercent + " " + ucMethod + "'";
s += " onClick='setDevice(" + i + ", \"DIM " + dimPercent + "\", " +
lcMethod + ");'> Dim";
if (! shortButtons) s += " " + dimPercent + "%";
s += " </button></td>";
document.write(s);
// ... and Bright button
s = "<td><button type='button'";
if (showHovertext)
s += "title='" + devices[i] + " BRIGHT " + brightPercent + " " + ucMethod + "'";
s += " onClick='setDevice(" + i + ", \"BRIGHT " + brightPercent + "\", " +
lcMethod + ");'> Bright";
if (! shortButtons) s += " " + brightPercent + "%";
s += " </button></td>";
document.write(s);
}
document.writeln("</tr>");
}
document.writeln("</table>");
if (showStatus)
window.status = "Thanks for using Web X10der v" + version;
}
// -->
</script>
</head>
<body bgcolor="#A9A9A9">
<script type="text/JavaScript" language="JavaScript">
<!--
generate();
// -->
</script>
<noscript>
<h3>You must have JavaScript enabled to use this page.</h3>
</noscript>
<!-- vim: set tabstop=4 shiftwidth=4 expandtab lines=44 columns=120: -->
</body>
</html>
tuve que dividir el scrip en dos porquie no me cabia por lo largo , espeero que me puedan ayudar